|
Thanks,
I am suppose to be calling on subs and not have everything underneath the button calculate. I am trying the suggestion up top, but not sure where to copy and paste this section and how to call upon it.
Thank you,
ibok23
|
|
|
|
|
I think I figured it out. I created its own private sub then called for the sub. I wasn't suppose to put it under the btn for that box. My fault.
Thanks for the suggestions and examples - it helps.
Tammy
Thank you,
ibok23
|
|
|
|
|
ya.. i think u were getting the errors from afew posts earlier from the sub that you made with the "_textchanged" at the end of it.. since you never made a sub called exactly "costofrooms", but rather "costofrooms_textchanged". the error occured b/c there was no sub existing that you were tryting to call (costofrooms()), right?
all working now?
------------------------
Jordan.
III
|
|
|
|
|
As far as I know. I am just in the process of commenting on the code itself.
Thank you,
ibok23
|
|
|
|
|
alrighty. hope i was of some assistance.
and remember... CAMEL CASTING.
------------------------
Jordan.
III
|
|
|
|
|
don't worry you were. Thanks.
Tammy
Thank you,
ibok23
|
|
|
|
|
I'm creating an n-tier application that I want to implement decent error handling in. Its probably best to describe an Example and request comment.
The presentation layer is a form to Redeem a coupon. The user enters into the form details and has a submit button.
The business logic layer (Redeem function) will do some basic checking such as the coupon hasnt been validated already or cancelled or expired and if OK will perform the status chnage to indicate that it has now been redeemed.
The data access layer consists of simple getstatus and changestatus functions to call stored procedures.
In this example the data access or business logic layers could fail as a result of a whole host of items - such as SQL problems or invalid status for the action.
If I went with the approach I'm more familar with which is from a VB6 background - I could return different codes from the functions and track in the calling function and control the actions as a result of these different problems. I'd probably set up a enumeration in a interface file used by all components - so that I dont just use magic numbers but that the return code is either success or a code indicating cause of the problem. But I'd still need some exception handling to deal with all other eventuallities.
The more .NET approach may be to create custom exceptions for the application. And throw these errors instead of return codes. This would allow the exceptions to bubble to a layer where they are dealt with. The functions would then return either a success or throw an exception.
Only small simple functions that only require a success or failure would possibly use return code values other than success.
This would require some custom exceptions created for situations like ItemDoesntExist and InvalidStateTransition but I could see this being a nice approach as all functions would have exception handlers and a pretty standard template would be used by deafult on all functions with addition of catch statements for more specifics to be dealt with.
In above example I'd have a different form that would be called if something didn't exist to if the action was invalid because say the status' were incorrect. This is why I'd need specific reasons as to why something had failed.
Any thoughts on these two approaches ? I could use either.....
|
|
|
|
|
I think that it would be better to use Exceptions as the .NET framework itself uses it.
"I think there is a world market for maybe 5 computers"
Thomas Watson, chairman of IBM, 1943
"There is no reason anyone would want a computer in their home"
Ken Olson, chairman & founder of Digital equipment, 1977
"This 'telephone' has too many shortcomings to be seriously considered as a means of communication. The device is ingerently of no value to us."
Western Union internal memo, 1876
"640 K ought to be enough for anybody."
Bill Gates, 1981
"Computers in the future may
|
|
|
|
|
I add data using the following method:
Open "text.txt" For Append As #1
Write #1, Display.Text, ID.Text
Close #1
'next section adds data in text.txt to a list box
Open "text.txt" For Input As #1
x = 1
Do While Not EOF(1)
Input #1, username, user_id
List1.AddItem username
x = x + 1
Loop
Close #1
How do i delete the data which i select from the list box??
|
|
|
|
|
Using a text file, it's a pain in the butt.
What you have to do is, literally, rewrite the text file.
1) Open the text file you have -> we'll call it source.txt
2) Open a second text file -> we'll call it target.txt
3) Read a line from source.txt
4) Is this the line you want to delete?
No -> Write this line to Target.txt
5) Read the next line from source.txt until you reach the end of the file.
6) Close both files
RageInTheMachine9532
|
|
|
|
|
Heres what i have so far:
Open "source.txt" For Append As #1<br />
Open "target.txt" For Input As #2<br />
<br />
x = 1<br />
Do While Not EOF(1)<br />
Input #1, UserName, UserID<br />
If Not UserName = NewUser.User.Selected(nIndex) Then 'Is this kinda what you meant in step 4? NewUser is form name, User is list box name.<br />
Print #2, UserName, UserID<br />
End If<br />
x = x + 1<br />
Loop<br />
Close #1<br />
Close #2
Its not writing the taget.txt
|
|
|
|
|
Pugzley wrote:
Open "source.txt" For Append As #1
Open "target.txt" For Input As #2
x = 1
Do While Not EOF(1)
Input #1, UserName, UserID
If Not UserName = NewUser.User.Selected(nIndex) Then
Print #2, UserName, UserID
End If
x = x + 1
Loop
Close #1
Close #2
There's a few thing wrong with this:
1) What's with 'x'? It's never used in this algorithm so remove it.
2) Your reading from your target file and write to your source file. Not good unless you want to erase all of your data.
3) Open your source file for input and your target file for output, not append. Remember, you have to rewrite your entire file to do this.
Fixed version:
Open "source.txt" For Input As #1
Open "target.txt" For Output As #2
Do While Not EOF(1)
Input #1, UserName, UserID
If Not UserName = NewUser.User.Selected(nIndex) Then
Print #2, UserName, UserID
End If
Loop
Close ' Close with no parameters will close ALL open files you opened with Open.
RageInTheMachine9532
|
|
|
|
|
OK, now it copies the data to the other file, however it includes the data that I want to exclude
|
|
|
|
|
Then the compare is not coming up with the correct result:
Open "source.txt" For Input As #1
Open "target.txt" For Output As #2
Do While Not EOF(1)
Input #1, UserName, UserID
If Not UserName = NewUser.User.Selected(nIndex) Then
Print #2, UserName, UserID
End If
Loop
Close ' Close with no parameters will close ALL open files you opened with Open.
You're going to have to step through the code, as it's running, and make sure that what you're comparing is what your expecting.
RageInTheMachine9532
|
|
|
|
|
What you have to do is, literally, rewrite the text file.
1) Open the text file you have -> we'll call it source.txt
2) Open a second text file -> we'll call it target.txt
3) Read a line from source.txt
[b]4) Is this the line you want to delete?
No -> Write this line to Target.txt[/b]
5) Read the next line from source.txt until you reach the end of the file.
6) Close both files
How do I do the section in bold??
|
|
|
|
|
Anonymous wrote:
What you have to do is, literally, rewrite the text file.
1) Open the text file you have -> we'll call it source.txt
2) Open a second text file -> we'll call it target.txt
3) Read a line from source.txt
4) Is this the line you want to delete?
No -> Write this line to Target.txt
5) Read the next line from source.txt until you reach the end of the file.
6) Close both files
How do I do the section in bold??
If UserName <> SelectedUserName Then
Print #2, UserName, UserID
End If
If this is not the line we are looking for, write it to the target file...
RageInTheMachine9532
|
|
|
|
|
I got most of it working except for the part where I remove ALL items that are selected. The program is just removing the items that are high lighted, instead of all that are selected.
<br />
Open "source.txt" For Input As #1<br />
Open "target.txt" For Output As #2<br />
Do While Not EOF(1)<br />
Input #1, UserName, UserID<br />
<br />
If Not NewUser.User.List(User.ListIndex) = UserName Then<br />
Write #2, UserName, UserID<br />
End If<br />
Loop<br />
Close<br />
<br />
Kill "source.txt"<br />
Name "target.txt" As "address.add"
How do i delete all selected items??
|
|
|
|
|
Ahhh! You never mentioned that before!
To do that, you have to compare each selected item to the one you've read. All you do is loop through all of your selected items. I can't give you the EXACT code because I don't know how your keeping track of what's been selected in what control:
Dim i As Integer
Open "source.txt" For Input As #1
Open "target.txt" For Output As #2
Do While Not EOF(1)
Input #1, UserName, UserID
For i = 0 to NewUser.User.List.Count - 1 ' Or whatever your tracking them in
If NewUser.User.List(i) = UserName Then
Exit For ' If the a match is found, skip to the next line in the file
End If
Write #2, UserName, UserID ' This statement will only execute if the selected list
' does NOT match the current line in the file
Next
Loop
Close
RageInTheMachine9532
|
|
|
|
|
User is the name of the list box and its style is set to check box, NewUser is the for name.
This code only removes the highlighted item in the list box, not the selected items.
I have tried usin List in the for statement instead of ListCount, and i still get the same result.
Also, this code makes repeated copies of the items not highlighted.
Dim i As Integer
Open "source.txt" For Input As #1
Open "target.txt" For Output As #2
Do While Not EOF(1)
Input #1, UserName, UserID
For i = 0 To NewUser.User.ListCount - 1
If NewUser.User.List(Recipients.ListIndex) = UserName Then
Exit For
End If
Write #2, UserName, UserID
Next
Loop
Close
|
|
|
|
|
Anonymous wrote:
Dim i As Integer
Open "source.txt" For Input As #1
Open "target.txt" For Output As #2
Do While Not EOF(1)
Input #1, UserName, UserID
For i = 0 To NewUser.User.ListCount - 1
If NewUser.User.List(Recipients.ListIndex) = UserName Then
Exit For
End If
Write #2, UserName, UserID
Next
Loop
Close
Where did Recipients.ListIndex come from? The I is there to index through the selected Items. That's why you keep getting the same line over and over again.
Since your using the items from a ListBox control, the selected items are indexed by the SelectedItems property:
Dim i As Integer
Open "source.txt" For Input As #1
Open "target.txt" For Output As #2
Do While Not EOF(1)
Input #1, UserName, UserID
For i = 0 To ListBox.SelectedItems.Count - 1
If ListBox.SelectedItems(i) = UserName Then
Exit For
End If
Write #2, UserName, UserID
Next
Loop
Close
RageInTheMachine9532
|
|
|
|
|
With thos changes made the program now comes up with a compile error: Method or data member not found. And it highlights the SelectedItems part of the for statement.
The Recipients.ListIndex was there to compare UserName and the name displayed in the list box.
|
|
|
|
|
OK. The code is good if and only if you get the name of your listbox correct.
But, I've simplified the code even further. The only possible hitch is getting the the ListBox name correct. I'm ASSUMING you called it "NewUser.User.List":
Dim i As Integer
Open "source.txt" For Input As #1
Open "target.txt" For Output As #2
Do While Not EOF(1)
Input #1, UserName, UserID
If Not NewUser.User.List.SelectedItems.Contains(UserName) Then
Write #2, UserName, UserID
End If
Loop
Close
RageInTheMachine9532
|
|
|
|
|
The name of the list box is actually "User". Either way, whenever I run the program, I get an error and it highlights the "SelectedItems" part of the code.
|
|
|
|
|
Pugzley wrote:
The name of the list box is actually "User".
The SelectedItems property is not throwing the error, it's the class path your using to get it. If the ListBox on the Form is call User then the code should look like this:
Dim i As Integer
Open "source.txt" For Input As #1
Open "target.txt" For Output As #2
Do While Not EOF(1)
Input #1, UserName, UserID
If Not User.SelectedItems.Contains(UserName) Then
Write #2, UserName, UserID
End If
Loop
Close
I'm assuming that this code is on the form that the ListBox is on. If not, you'll have to modify the line to get to the ListBox, like specifying which form the listbox is on.
RageInTheMachine9532
|
|
|
|
|
After much trial and error, I came up with this:
Open "source.txt" For Input As #1
Open "target.txt" For Output As #2
Do While Not EOF(1)
For n = 0 To (User.ListCount - 1)
Input #1, UserName, UserID
If Not User.Selected(n) = True Then
Write #2, UserName, UserID
End If
Next
Loop
Close
This seems to work fine.
|
|
|
|