Solved

I want a Code

Posted on 2004-03-24
5
146 Views
Last Modified: 2010-05-01
I want to read a text file in a folder atonce it is saved in the folder.
Thing is the file will be exist in the folder only for one or two seconds before that I have to read that, after couple of seconds file will be automatically deleted by some other application so our program has to wait for the arrival of the file once it comes in the folder our program has to read the file.. Will you please give me the code.
Expecting your favourable and prompt reply.

0
Comment
Question by:Ezhil7
5 Comments
 
LVL 15

Accepted Solution

by:
SRigney earned 63 total points
ID: 10668839
If you are using .Net you can set up a filewatcher and read the file that way.  

http://www.ftponline.com/vsm/2004_02/magazine/columns/gettingstarted/

0
 
LVL 3

Assisted Solution

by:Bobeo
Bobeo earned 62 total points
ID: 10669050
This worked for me in VB 6

You need a Microsoft Scripting Runtime Reference on your project and a timer and a textbox on your form.  Set the timer interval to 100


Dim FSO As New FileSystemObject
Dim FileName As String
Dim TXT As TextStream
Dim FileText As String
dim FileRead as boolean

Private Sub Form_Load()
FileRead = False
end sub

Private Sub Timer1_Timer()
if FileRead = False then
On Error GoTo Errors
FileName = App.Path & "\Text.txt"
Set TXT = FSO.OpenTextFile(FileName, ForReading, False)

FileText = TXT.ReadAll
Text1 = FileText

FileRead = True
Timer1.Enabled = False

end if

Exit Sub

Errors:
Exit Sub
End Sub


Hope it works for you!
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

831 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