Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Inet1 Sub routine Question

Status
Not open for further replies.

valicon

MIS
Sep 26, 2000
125
US
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 feel like I left you stranded on this.

One way to do what you want is to get rid of the Command1_Click( ) routine and just put the code into your Form_Load( ) instead.

Actually if you don't need a GUI for this program at all (no form):
[ul][li]Create a new VB Project.
[li]Delete the form you get by default (over in the Project Explorer right-click on the form, select "Remove Form1").
[li]Create a code module (Project Explorer, right-click the Project icon, select "Add > Module").
[li]Create a Sub Main( ).
[li]In the project properties, set Sub Main( ) as the startup object.[/ul]
Then put all of your code in Sub Main( ). The module can also have any other subroutines or functions you want to use. This is basically how a "console" VB program is made.
Code:
Sub InetGet(URL As String, OutF As String)
  :
End Sub

Sub Main( )
  InetGet "[URL unfurl="true"]http://whatever.com/stuff.htm",[/URL] "whereever.txt"
  InetGet "[URL unfurl="true"]http://www.someplace.com",[/URL] "keepit.htm"
  MsgBox "Done!"
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top