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?
raymosheaAsked:
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.

Ryan_KemptCommented:
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
Loop
Close #1

Open in new window

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

Open in new window

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

0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

taskyCommented:
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
dentabCommented:
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
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dentabCommented:
Thank you, I hope that helped.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.