raymoshea
asked on
visual basic automatic updater
i'm using visual basic 6.0 and i am trying to make a gui that automatically reads and displays the contents of a file every hour. can this be done?
I do apologize, I should have had that clear the listbox before reading in the file again. Be sure to add the following to the top of the previous code snippet:
lstMyListbox1.Clear
Yes, you can make it poll a file every hour. If however you would like to update as soon as the file changes, this is also possible without polling the file. Let me know, I will poste it.
If you want to poll, then use a timer control to call a routine.
Rayan's example (above) would populate a listbox. There is a minor problem with his code if you did wish to use it - "Input #1, d" aught to be "Line Input #1, d"
This is because commas can split up the line reading without the "Line" prefix.
My function below could be pasted into a form or a module and used to return the entire contents of a file. Also as explicit filenumbers are not used, it will not interfear with any other calls.
example usage:
text1.text = getFileContents(app.path & "\text1.txt")
To get the file, try this sub routine
If you want to poll, then use a timer control to call a routine.
Rayan's example (above) would populate a listbox. There is a minor problem with his code if you did wish to use it - "Input #1, d" aught to be "Line Input #1, d"
This is because commas can split up the line reading without the "Line" prefix.
My function below could be pasted into a form or a module and used to return the entire contents of a file. Also as explicit filenumbers are not used, it will not interfear with any other calls.
example usage:
text1.text = getFileContents(app.path & "\text1.txt")
To get the file, try this sub routine
Function getFileContents(ByVal myFilePath As String) As String
Dim ff As Integer, strIn as String
ff = FreeFile 'Gets available file number
Open myFilePath For Binary As ff
strIn = String(Lof(ff)," ")
Get #ff, 1, strIn
Close ff
getFileContents = strIn
End Function
If you use a timer, set the interval to 60000 (1 minute or 60 seconds) and then have a variable which you increment until you hit 60 minutes. Then use any code above to read the file.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Thank you, I hope that helped.
Open in new window