Load file but only if it has been modified....

What I am trying to do is this....

On program start, Load a .txt file from network drive.
Check if the .txt file has changed (maybe by checking the last modified date/time of the files properties..)????
If the .txt file has changed, load the file again.
If the .txt file hasn't changed do nothing.

Any pointers anyone, adnd is this the best way to do this?

Many thanks,

Dave.
wildarmsdaveAsked:
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.

Mike TomlinsonMiddle School Assistant TeacherCommented:
I'm not sure I understand your description...

You load a .txt file at program start...got it.  

Are we supposed to store the modified date/time now?  (after displaying the text file on a form)

Now when should we check to see if it has changed?  Do you want to use a Timer and check to see if the file has changed every 30 seconds or so?  If it has, then load the file again and update the file contents on your form?
0
Leo EikelmanDirector, IT and Business DevelopmentCommented:
You can use this to check when the find was last modified

Private Sub Form_Load()
Dim FSO As Scripting.FileSystemObject 'Set reference to Microsoft Scripting Runtime
Set FSO = New Scripting.FileSystemObject
Dim File As Scripting.File

If FSO.FileExists("C:\EOW-3.txt") Then
Set File = FSO.GetFile("C:\EOW-3.txt")


MsgBox (File.DateLastModified)

Then you can use something like this

if DateDiff("h", Date, File.DateLastModified) > 24 then

// Do whatever you need to do

Where Date is the current date.

so with this you can check if the file was last modified in a certain amount of time.


Hope this helps ,

Leo
0
Mike TomlinsonMiddle School Assistant TeacherCommented:
You can do it natively in VB6 with FileDateTime():

    Dim modified As Date
    modified = FileDateTime("c:\somefile.txt")
    MsgBox modified
0
Ultimate Tool Kit for Technology Solution Provider

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 now.

wildarmsdaveAuthor Commented:
I think leikelman has hit the nail on the head although I don't have time to try his code yet. I'll have a look later...

Idle Mind, you are correct with what I am wanting to do..

Currently the program opens the file every 60 seconds and if the data has changed, displays it on screen. This is fine as all the data contains is a few lines of text. However, the data will now contain images and tables which will increase the file size. I would sooner check if the file has changed BEFORE I load it from the network. The program will be running on 60+ PC's so don't want to overload our network..

Dave.
0
Leo EikelmanDirector, IT and Business DevelopmentCommented:
Glad the code helps : )

Leo
0
Mike TomlinsonMiddle School Assistant TeacherCommented:
So something like this...

Option Explicit

Private fileName As String
Private lastModified As Date

Private Sub Form_Load()
    fileName = "c:\someFile.txt"
    lastModified = FileDateTime(fileName)
    LoadFile fileName, Text1
End Sub

Private Sub LoadFile(ByVal file As String, ByVal tb As TextBox)
    If Dir(file) <> "" Then
        Open file For Binary Access Read As #1
        tb.Text = Input(LOF(1), 1)
        Close #1
    End If
End Sub

Private Sub Timer1_Timer()
    Dim curModified As Date
    curModified = FileDateTime(fileName)
    If curModified <> lastModified Then
        lastModified = curModified
        LoadFile fileName, Text1
    End If
End Sub
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
wildarmsdaveAuthor Commented:
Sorry for the late reply!!

Both solutions are fine but I have a bit of a dilema regarding to award the points to (and I don't want to upset anyone!!)

leikelman's code got me up and running but then Idle_Mind  posted his code which was better than mine (not difficult!) so I decided to use that instead. What do you guys think??
0
Leo EikelmanDirector, IT and Business DevelopmentCommented:
split points
0
Mike TomlinsonMiddle School Assistant TeacherCommented:
Split 'em...points are no big deal...    =)
0
wildarmsdaveAuthor Commented:
Ok lads. I just wanted to make sure you were both happy with that before I split them. Thank you both once again for your quick responses and class answers!
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.