Hi all,
I have the code below which will go out and retrieve data from a webpage and then write it to a text file. When the app is run, you must press the button to start the process. My question is what do I need to add/delete from the code to make the app automatically perfom this function when run instead of having to press the button? This little app will need to go out to three different websites and retrieve data and write that data to three diferent text files, how can I add the functionality to have this code go to more than one URL and write to more than one file? I am new to VB and I am still learning, any help will be great! Thanks. Here's the code:
Private Sub Command1_Click()
'Error Trapping
On Error GoTo errorHandler
'Display message in Text2
Text2.Text = "Retrieving data from " & Text1.Text
'Set timeout to 20 seconds
Inet1.RequestTimeout = 20
'Retreive the code from the URL in Text1
Text2.Text = Inet1.OpenURL(Text1.Text)
Dim iFB As Integer
iFB = FreeFile 'Get next available file buffer
Open "C:\MyFile.txt" For Output As #iFB 'Open the file to write to disk
Print #iFB, Text2.Text 'Write out the contents of the textbox
Close iFB 'Close the file buffer
Exit Sub
errorHandler:
Text2.Text = "An error has occured! & vbNewLine & Err.Description"
Err.Clear
End Sub
Private Sub Form_Load()
Text1.Text = "
End Sub
I have the code below which will go out and retrieve data from a webpage and then write it to a text file. When the app is run, you must press the button to start the process. My question is what do I need to add/delete from the code to make the app automatically perfom this function when run instead of having to press the button? This little app will need to go out to three different websites and retrieve data and write that data to three diferent text files, how can I add the functionality to have this code go to more than one URL and write to more than one file? I am new to VB and I am still learning, any help will be great! Thanks. Here's the code:
Private Sub Command1_Click()
'Error Trapping
On Error GoTo errorHandler
'Display message in Text2
Text2.Text = "Retrieving data from " & Text1.Text
'Set timeout to 20 seconds
Inet1.RequestTimeout = 20
'Retreive the code from the URL in Text1
Text2.Text = Inet1.OpenURL(Text1.Text)
Dim iFB As Integer
iFB = FreeFile 'Get next available file buffer
Open "C:\MyFile.txt" For Output As #iFB 'Open the file to write to disk
Print #iFB, Text2.Text 'Write out the contents of the textbox
Close iFB 'Close the file buffer
Exit Sub
errorHandler:
Text2.Text = "An error has occured! & vbNewLine & Err.Description"
Err.Clear
End Sub
Private Sub Form_Load()
Text1.Text = "
End Sub