|
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.
|
|
|
|
|
Hello
I am working in VB6 with SQL Server 2000. I need to store complex type of Text like Mathemetical Equations we have typed in RichTextBox Control. RichTextBox Control Stores these equations as a Object or we can say a picture. now can anyone tell me how to get these Objects and Text from RichTextBox and store into my SQL Server Column which is of DataType VARBINARY as the text I want to store is of both Image Type and Text as well(RichTextBox can store both Images and Formatted Text inside it). so I choosed VARBINARY. Only this datatype is capable of handling mathematical equations..
Kindly guide me about it
Syed Usman Shaukat Ali
|
|
|
|
|
I have some problems about animation control. For Example , there is a (fly)picturebox on the left on the form. If i move a (Hands)picturebox, to the fly, the fly disappear.
Can another show me how to do it? thanks
|
|
|
|
|
since there isnt a post yet ill post my worthless $0.02...
i havent done anything with animation and m going to get yelled at by, if not you, then the person appropriate for this response...
would this happen to b an opacity problem? are one of the objects opaque and are overlapping the other when atop it?
------------------------
Jordan.
III
|
|
|
|
|
Situation: In may Web page I have RequiredFieldValidators. I have button Back. I need that when I push the Back button, page redirects to other page (Response.Redirect("URL")). But its don't work, because of RequiredFieldValidators. I tried: ReqNAME.Enabled = False, but it's doesn't work too...( But when I Disable this validator at all, not in scripting progress in Button_Clik event, its works.... Why it is so? I tried with Button_Click change other validator Properties, no reactions... ?
|
|
|
|
|
I am needing to shortem my code up. I keep on having to repeat myself so I am trying to do subbing. I am getting an error. It is saying that I have not declared additionalguest - this is what I have
Private Const additionalguest as double = ((nudguest.text - 2) * 10) * Val(numberofdays.text))
If nudguest.text > 2 then
additionalguestcharge.text = additionalguest
Could anybody tell me what I may be doing wrong?
Thank you,
ibok23
|
|
|
|
|
ibok23 wrote:
Private Const additionalguest as double = ((nudguest.text - 2) * 10) * Val(numberofdays.text))
where is this located?
ibok23 wrote:
If nudguest.text > 2 then
additionalguestcharge.text = additionalguest
...where is this located?
since you have declared additionalguest as a private variable, it can only be accessed in the method it is defined, unless you declare it at class/module level. if you are only using the private variable in 1 method, declare it in the same sub that the if statement is in.
..or..
is the private variable already declared in the same sub as the if statement? in this case, post more code.
------------------------
Jordan.
III
|
|
|
|
|
OK. You've got a problem with the way your declaring your variables:
ibok23 wrote:
Private Const additionalguest as double = ((nudguest.text - 2) * 10) * Val(numberofdays.text))
The 'Const' means that the additionalguest variable will be a constant. Once it's defined, it can never be changed. You can't use the code in your if statement to change it. What you need to do is change the declaration of additionalguest:
Private additionalguest As Double = ((nudguest.text - 2) * 10) * Val(numberofdays.text))
For future reference, error messages are extremely important when asking us questions. Without the error message, we can only guess at what's wrong. Also, posting the code that you did was very helpful, keep it up! You can never post too much code! ...Well, within reason...
RageInTheMachine9532
|
|
|
|
|
It is still saying that the additionalguest is not declared. This is what I wrote.
This is all under the button to calculate.
Private additionalguest as double = ((nudguest.text - 2) * 10) * Val(numberofdays.text)) [I have an error on the last parenthesis - It says end of statement expected.]
if nudguest.text > 2 then
additionalguestcharge.text = additionalguest [I have an error under additonaguest - it says the additionalguest has not been declared]
additionalguestcharge.text = format (additionalguest, "currency")[I have an error under additonaguest - it says the additionalguest has not been declared]
Well what am I doing wrong now? lol
Thank you,
ibok23
|
|
|
|
|
ibok23 wrote:
Private additionalguest as double = ((nudguest.text - 2) * 10) * Val(numberofdays.text)) [I have an error on the last parenthesis - It says end of statement expected.]
You have to many parenthesis here, count the oppening and closing brackets, there should be one closing bracket ")" for each opening bracket "(".
I Think the code should be..
Private additionalguest as double = ((nudguest.text - 2) * 10) * Val(numberofdays.text)
Nadroj wrote:
since you have declared additionalguest as a private variable, it can only be accessed in the method it is defined
Nadroj is quite write, you cannot access the variable outside the code block in which you declared. From the code snipet you posted, we cannot see if you are doing this.
Have you tried declaring it a as class variable?
EG
Public Class myClass<br />
<br />
Private additionalguest as double<br />
<br />
'..other class declarations, methods etc<br />
<br />
Private Sub CalcCharges<br />
additionalguest = ((nudguest.text - 2) * 10) * Val(numberofdays.text)<br />
<br />
if nudguest.text > 2 then additionalguestcharge.text = additionalguest<br />
End Sub
Hope this helps
Regards
Wayne Phipps
____________
Time is the greatest teacher... unfortunately, it kills all of its students
LearnVisualStudio.Net
|
|
|
|
|
ibok23 wrote:
This is all under the button to calculate.
Private additionalguest as double = ((nudguest.text - 2) * 10) * Val(numberofdays.text)) [I have an error on the last parenthesis - It says end of statement expected.]
OK. Since this is inside the Calculate button CLick handler, you don't need the Private. Also, the error emssage you got is because the parenthesis don't match up. You have 3 open parenthesis and 4 closing. They need to match exactly:
Dim additionalhuest as Double = ((nudguest.text - 2) * 10) * Val(numberofdays.text)
As for the rest, your best bet is to copy the entire Calculate button Click code to a post here. Paste between <pre> and </pre> tags, like this:
<pre>Private Sub Calculate_Click(...)
Some more code shows up here...
and some more...
End Sub</pre>
When the message is posted, it'll come out looking like this:
Private Sub Calculate_Click(...)
Some more code shows up here...
and some more...
End Sub
EDIT: I forgot, don't retype the code you have in your posts. Always Copy and Paste it between a couple of <pre> and </pre> tags or a couple of <code> and </code> tags.
RageInTheMachine9532
|
|
|
|
|