Solved

I want a Code

Posted on 2004-03-24
5
144 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

920 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now