Writing and reading a text file simultaneously in vb6

C

chook.harel

I need to build a program that will fill a text file, which means,

Append certain text to it...

Now this program should run on several computers and each one of them
should append to the same file

Can visual basic handle it? Or it will give me errors when two tries to
write at the same time.


Now moreover, a second process should simultaneously read from the file
(needs to read the first line like in a FIFO stack)


Thanks in advance,

Chen.
 
R

Ron Weiner

What have you tried?

Something like this MAY work for the appends, but you will have to test

Dim f As Long
f = FreeFile
Open [FilePathAndName.txt] For Append Shared As #f
Print #f, "</y>"
Close #f

Something like this may work for the reads, but you will have to test

Dim f As Long, strMyStr as String
f = FreeFile
Open [FilePathAndName.txt] For Input Shared As #f
Do While not EOF(f)
strMyStr = Input(100,#f) ' Reads 100 chars from the file at a time
Loop
Close #f

Yoou might also want to look at the Write# and Input# statements too.
Depending on the data you are reading and writing you may be better off.
The really big problem, I suspect will be how can the Read file operation
know where the end of the file is when the end of the file is constantly
meing moved further and further back by the other processes.

I recommend that you put some code together and start testing. Get back to
us if / when you run into problems. Good luck with your project.
 
B

Brendan Reynolds

It is the nature of text files that they can only be safely used by a single
user (or process) at a time. They include no mechanism to handle concurrency
issues.
 
C

chook.harel

But still for implementing fast jobs their better than establishing a
DATABASE (which will evantually be my last resort)

About the reading of the file.
It's not that hard i think, because i can make the records fixed, and
then maybe just check file size
or just read a record and so on.
by the way, the read operation should also deletes the record it read,
so it's not that easy aswell...
Can you delete a record from the beginning ? I'm not sure on how that
works ....
 
R

Rob Oldfield

You mean that for the sake of efficiency I should ditch SQL server and put
everything in text files?
 
B

Brendan Reynolds

If you're using Access, you're using a database, and if you're not using
Access, one wonders why we are having this conversation in an Access forum?

That aside, if you want to ignore my advice (as you are certainly entitled
to do) and attempt to use text files in place of a multi-user database,
you'll need to open the files in random or binary mode. Information about
this kind of thing has become increasingly hard to find in official
Microsoft sources in recent years. I couldn't find anything at MSDN, you
might have to resort to Google, or old DOS BASIC books if you can find them.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top