|
-
Dec 5th, 2000, 02:03 PM
#1
Thread Starter
New Member
I'm writing a program that will allow you to sift through a text file, one line at a time, and write to a new text or .mdb file. The problem I am having is that I cannot see how to stop the loop to wait for a user command. I am sure that it is something relatively simple, but I am completely new to VB (three months or so), and my VB skills are pretty small. Here's the code that I'm using:
Private Sub cmdStart_Click()
Open SelectedFile For Input As #1
Do While Not EOF(1) ' Loop until end of file.
Input #1, txtString
txtTextString.Text = txtString
'Wait here until user presses one of a few command
'buttons to determine what to do with the string.
Loop
Close #1
End Sub
Any help would be greatly appreciated.
PSurge
"That which is immobile must suffer destruction"
-Emanual Lasker
-
Dec 5th, 2000, 02:11 PM
#2
Junior Member
Use some form-level variable to let you know what was clicked. When the button is clicked, set the variable
accordingly.
=======================================
Dim actionInt As Integer
Private Sub cmdStart_Click()
actionInt = 0
Open SelectedFile For Input As #1
Do While Not EOF(1) ' Loop until end of file.
Input #1, txtString
txtTextString.Text = txtString
Do While actionInt = 0
DoEvents
Loop
If actionInt = 1 Then
...your code here
ElseIf actionInt = 2 Then
...your code here
...etc...
End If
Loop
Close #1
End Sub
Then, when any button is pressed, simply set actionInt:
Private Sub cmdAction1_Click()
actionInt = 1
End Sub
Private Sub cmdAction2_Click()
actionInt = 2
End Sub
...etc...
Hope this is of some help.
Guinness
-
Dec 5th, 2000, 02:18 PM
#3
Here...
Try this...
Set a checker variable:
Code:
Dim Cont as integer ' (Continue)
then...
Code:
Private Sub cmdStart_Click()
Cont = 0
Open SelectedFile For Input As #1
Do While Not EOF(1) ' Loop until end of file.
Input #1, txtString
txtTextString.Text = txtString
Do Until Cont = 1
DoEvents
Loop
Cont = 0
'In the command buttons that are the choices
'Add Cont =1 as the last thing it does (so that code occurs before it triggers the continue)
Loop
Close #1
End Sub
this in command button:
Code:
Private sub Command1_Click()
'code
'code
'code
Cont = 1
end sub
Hope this helps!
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Dec 5th, 2000, 02:26 PM
#4
Junior Member
Another way?
Here's some pseudo code that demonstrates another way. The idea is to read the whole file at one time, close it, then deal with the lines as array elements.
- read the whole file into a string
- split that string into an array consisting of the lines
of files (using the Split function)
- then in the command button's click event you can deal with the current line of the file
- you can keep track of the current line number by using either a static variable (a var that does not get re-initialized to zero after each button click) or a global variable
Amanda
-
Dec 5th, 2000, 02:31 PM
#5
Thread Starter
New Member
geoff_xrx, Guinness
Thanks for all your help! Both of the Ideas
worked perfectly, but I tend to prefer geoffs method.
I didn't even know about the DoEvents function before,
but it seems that this is exactly what I was looking
for. It's interesting to note that if I search the
help for "wait", I don't get DoEvents, but I do get
it with "yield". Hmm...
Thanks Again!
PSurge
"That which is immobile must suffer destruction"
-Emanual Lasker
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|