tags:

views:

797

answers:

2

Want to know how to open a file in VB6 for shared writing.

+1  A: 

have you a piece of code?

normally, the syntax is Open "filename.txt" for MODE [Lock] as #FILENO

whereas MODE is one of Input, Output, Random, Append, Binary (Random is default) if you don't specify Lock, it normally shouldn't lock except on modes output and append.

don't forget to Close #FILENO after operation.

you might want to take a look at http://www.profsr.com/vb/vbless08.htm

regards

Atmocreations
A: 

Use Access and Lock, just like the manual says here. For example:

Open "file.txt" For Output Access Write Lock Shared As #Num

You'll need to choose the right mode (after the For keyword) depending on what you're doing: is it a text file or a binary file, are you appending to an existing file... There's more about files in the VB6 programmer's guide for instance here.

MarkJ
Please check the sample code which I'm trying, whether the command2 code is correct. Even though I have specified Shared mode, it's giving me error on command2 - ---------------------Private Sub Command1_Click() Open "d:\mrudula\test.log" For Output Access Write Shared As #1 Write #1, "testing1.."End SubPrivate Sub Command2_Click() Open "d:\mrudula\test.log" For Output Access Write Shared As #2 Write #2, "testing2.."End SubPrivate Sub Form_Unload(Cancel As Integer) Close #1 Close #2End Sub
You can't open the same file twice on two different unit numbers from the same program. Try creating two separate test programs that write to the same file. You shouldn't get errors then. Although they might overwrite each other's file changes, obviously.
MarkJ