# 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?
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
Absolutely it can be. I would likely use a Timer object that you can drag-and-drop and enter the delay for. I'll also post up the code to read and display text (in a listbox).
Open "C:\myCoolFile.txt" For Input As #1
Do While Not EOF(1)
Input #1, d
Loop
Close #1

0
Commented:
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

0
Commented:
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

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

0
Commented:
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.
0
Commented:
rather than increment a variable, I would reccomend a using a module-scope variable.

In for forms general declarations
Dim waitTime As Date

then set the variable using DateAdd

The timer can then just check
If now >= waitTime Then...
... call file routine
End If
0

Experts Exchange Solution brought to you by