Stepping through file...

Hi guys,

I need to read a file line by line to get some test logins and passwords e.g line one is

login password

I'm posting this to a script in a form using Inet.execute, now here's the prob, it works fine, but what I need to know is how read one line, then process this to the form, then read the next line and process this to the form, etc etc, at the moment it's just looping through all the way to the last line and then only processing that line, if I try to include the inet.execute every loop it says the last process is still executing.

How I can I execute each line in the file? Furthermore, can I use a timer somehow to get this function to go through the file again after a certain period i.e after 1 second, after 30 seconds, etc? without having to click the command button again? Here;s my code, thanks for any help.

Private Sub cmdPOST_Click()
   picTic.Visible = True
   txtData.Text = ""
   
   Dim fnum As Integer
   Dim file_name As String
   Dim got_file As Boolean
   Dim txt As String
   
   Dim i As Integer
   Dim sArray As Variant
   
    ' Get the file's name.
    file_name = App.Path
    If Right$(file_name, 1) <> "\" Then file_name = file_name & "\"
    file_name = file_name & "logins.txt"
     
    ' Open the file.
    fnum = FreeFile
    On Error Resume Next
    Open file_name For Input As fnum
    got_file = (Err.Number = 0)
    On Error GoTo 0

    If got_file Then
        ' Read the text.
               Do Until EOF(fnum)
       
            Input #fnum, txt
            sArray = Split(txt)
            txtRemotePath.Text = "MNO=" & sArray(0) & "&PWD=" & sArray(1) _
            & "&BSB=NTV25"
     Loop
   Inet1.Execute txtURL.Text, "POST", txtRemotePath.Text, _
   "Content-Type: application/x-www-form-urlencoded"
   Text1.Text = Text1.Text & "yeah"
        ' Close the file.
    Close fnum
    End If
   
End Sub
GnatManAsked:
Who is Participating?
 
VbmasterCommented:
Just add a Timer control and set the Interval to 30000 (in case of 30 sec) or 60000 in case.. humm..

Inside the timer_timer event you can put code like...

  Private Sub Timer1_Timer

    Static Inside As Boolean
    If Inside Then Exit Sub
    Inside = True

    Call cmdPOST_Click()

    Inside = False

  End Sub

The static Inside varaible is probably really important here because sometimes maybe the cmdPost code will take more than 30sec (or whatever interval the timer is on) and you do not want two or more timer events to be executed simultaneous, that is just begging for trouble.

The Interval property of the Timer control is limited to 65535 ms, if you need a interval longer than 1 minute you can set the Interval to 60000 ms (1 minute) and then add a static counter inside the timer event. Increase the value with 1 every time the event is fired, and then if the timer equals the number of minutes you want to go between the calls to the code then set the variable to zero and run the cmdPOST code.
0
 
VbmasterCommented:
You can check the StillExecuting property to see if the control is busy with a earlier assignment. Perhaps you could implement a Do..Loop block after the Execute call like this

  'Place the Execute call here
  Do While Inet1.StillExecuting
    DoEvents
  Loop
  'The Inet control is free for next action here
0
 
AzraSoundCommented:
use the Line Input statement, e.g.
Line Input #FileNumber, A$

where filenumber is your file number and A is a string to receive the line from the file...then process that one line and perform the loop until EOF
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
AzraSoundCommented:
sorry i misread the question
0
 
AzraSoundCommented:
vbmaster is correct...you need to check that state...b/c when you use execute method it processes your request asynchronously which means it returns control back to your app right away...
0
 
GnatManAuthor Commented:
Thanks for all the help and the quick replies VBmaster and Azrasound, you guys are awesome! It really helped, got it working now. Cheers!
Nathan
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.