?
Solved

Auto Refreshing of text file opened for viewing

Posted on 2003-03-26
12
Medium Priority
?
163 Views
Last Modified: 2010-04-07
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
Comment
Question by:msivask
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +2
12 Comments
 
LVL 28

Expert Comment

by:vinnyd79
ID: 8209998
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
 

Author Comment

by:msivask
ID: 8210093
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
 
LVL 14

Expert Comment

by:puranik_p
ID: 8210174
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
Technology Partners: 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!

 

Author Comment

by:msivask
ID: 8211057
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
 
LVL 14

Expert Comment

by:puranik_p
ID: 8211105
goto project->references
add Microsoft Scripting Runtime
0
 
LVL 28

Accepted Solution

by:
vinnyd79 earned 2000 total points
ID: 8211277
' 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
 
LVL 28

Expert Comment

by:vinnyd79
ID: 8211316
Why add the overhead of FSO to the project just to open a text file?
0
 
LVL 14

Expert Comment

by:puranik_p
ID: 8215787
'coz its easy.
0
 
LVL 28

Expert Comment

by:vinnyd79
ID: 8219928
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
 

Expert Comment

by:CleanupPing
ID: 8531575
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
 
LVL 6

Expert Comment

by:GPrentice00
ID: 9441001
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
 
LVL 6

Expert Comment

by:GPrentice00
ID: 9441002
"Thanx for your code .It works fine"

0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question