Solved

Stepping through file...

Posted on 2000-05-09
6
144 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month10 days, 11 hours left to enroll

628 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