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?

[Webinar] Streamline your web hosting managementRegister Today

dentabConnect With a Mentor 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
waitTime = DateAdd("h",1,now)

The timer can then just check
If now >= waitTime Then...
  waitTime = DateAdd("h",1,now)
  ... call file routine
End If
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
  lstMyListbox1.AddItem d
Close #1

Open in new window

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:

Open in new window

The new generation of project management tools

With’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

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

Open in new window

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.
Thank you, I hope that helped.
All Courses

From novice to tech pro — start learning today.