• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 165
  • Last Modified:

Auto Refreshing of text file opened for viewing

I have a text file which is getting updated every 3 minutes by an application.
I have kept it open on my desktop for viewing .Is there any way I can automatically reresh the text file which is opened for viewing ,so that at any instant of time the content being viewed is the latest one

Thank u

Rgds
Siva

0
msivask
Asked:
msivask
  • 4
  • 3
  • 2
  • +2
1 Solution
 
vinnyd79Commented:
I don't know if there is a way without closing and re-opening the file. Try this, add a Timer and set the Interval property to 5000.

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Const WM_CLOSE = &H10

Private Sub Timer1_Timer()
' where "Testfile.txt - Notepad" is the caption of the Notepad window
CloseProgram ("Testfile.txt - Notepad")
Call ShellExecute(hwnd, "Open", ("C:\Testfile.txt"), "", App.Path, 1)
End Sub

Public Sub CloseProgram(ByVal Caption As String)
Dim Handle
Handle = FindWindow(vbNullString, Caption)
If Handle = 0 Then Exit Sub
SendMessage Handle, WM_CLOSE, 0&, 0&
End Sub
0
 
msivaskAuthor Commented:
hi vinnyd79

Thanx for your code .It works fine

Can you please explain it as waht each line does ..

As early as possible

Rgds
Siva
0
 
puranik_pCommented:
put a textbox on a form,
set
multiline = true
scrollbars = both

add a timer,
set
interval = 60000 '1 minute

Option Explicit
Private Sub Form_Load()
    Update
End Sub

Private Sub Timer1_Timer()
    Update
End Sub

Private Sub Update()
    Dim oFSO As New Scripting.FileSystemObject
    Dim TStr As Scripting.TextStream
   
    Set TStr = oFSO.OpenTextFile("c:/INSTALL.LOG")
   
    Text1.Text = TStr.ReadAll
   
    Set TStr = Nothing
End Sub
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
msivaskAuthor Commented:
Hi  puranik

In line  Dim oFSO As New Scripting.FileSystemObject

I am getting error User-defined type not defined

How to go about that

rgds siva
0
 
puranik_pCommented:
goto project->references
add Microsoft Scripting Runtime
0
 
vinnyd79Commented:
' declarations
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Const WM_CLOSE = &H10


Private Sub Timer1_Timer()
' where "Testfile.txt - Notepad" is the caption of the Notepad window
' call Close Program Sub,passing it the Window Caption to close
CloseProgram ("Testfile.txt - Notepad")
' re-open text file (shellexecute api will open any file with its default app
Call ShellExecute(hwnd, "Open", ("C:\Testfile.txt"), "", App.Path, 1)
End Sub

Public Sub CloseProgram(ByVal Caption As String)
Dim Handle As Long
' use FindWindow API to find the Handle of open Textfile window
Handle = FindWindow(vbNullString, Caption)
' if not found,exit
If Handle = 0 Then Exit Sub
' handle found,use sendmessage api telling the window to close(WM_CLOSE)
SendMessage Handle, WM_CLOSE, 0&, 0&
End Sub

0
 
vinnyd79Commented:
Why add the overhead of FSO to the project just to open a text file?
0
 
puranik_pCommented:
'coz its easy.
0
 
vinnyd79Commented:
Siva, there is a good api tutorial on Sendmessage and Findwindow api's here:

http://www.planetsourcecode.com/vb/scripts/ShowCode.asp?txtCodeId=42126&lngWId=1

0
 
CleanupPingCommented:
Hi msivask,
This old question (QID 20563656) needs to be finalized -- accept an answer, split points, or get a refund.  Please see http://www.cityofangels.com/Experts/Closing.htm for information and options.
0
 
GPrentice00Commented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

 -->Accept vinnyd79's comment as Answer

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER

GPrentice00
Cleanup Volunteer
0
 
GPrentice00Commented:
"Thanx for your code .It works fine"

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 3
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now