Solved

Stepping through file...

Posted on 2000-05-09
6
141 Views
Last Modified: 2010-05-02
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
0
Comment
Question by:GnatMan
  • 3
  • 2
6 Comments
 
LVL 7

Expert Comment

by:Vbmaster
ID: 2795284
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
 
LVL 28

Expert Comment

by:AzraSound
ID: 2795290
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
 
LVL 28

Expert Comment

by:AzraSound
ID: 2795292
sorry i misread the question
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
LVL 28

Expert Comment

by:AzraSound
ID: 2795300
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
 
LVL 7

Accepted Solution

by:
Vbmaster earned 23 total points
ID: 2795306
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
 

Author Comment

by:GnatMan
ID: 2795493
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

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question