Click to See Complete Forum and Search --> : Formatted READ and WRITE to a text file


Ali Habib
April 14th, 2001, 01:41 AM
Is there a way to do formatted READ and WRITE to a text file using VB. For example in fotran we have a function like
read(id,'(4i5,f10.0,i5)',err=110,end=110npnt,ntft,ntsv,ntip,damp,n411

The second parameter tells that read four integers of length 5, one float of length 10 with nothing after decimal and then one integer of length 5. At the end there is a variable list in which these values are retrieved,
Similarly for write we have
write(id,'(a80)') titl
This function writes titl to file in a 80 character long field.
How can we achieve similar functionality in VB

regards
ali.

UU4U
April 14th, 2001, 02:14 PM
Hi

1. You can use .ini files: if you have to archive fixed data, for code see
http://www.vb-world.net/demos/ini/index.html

2. just code for reading and writing data:

Dim InputData 'input an output string

Open fullpath_2_textfile For Input As #1
Line Input #1,InputData
Close #1

Open fullpath_2_textfile For Writing As #2
Write #2,InputData
Close #2

You may also open the number #1 and #2 or much more together like:

Dim InputData 'input an output string

Open fullpath_2_textfile For Input As #1
Open fullpath_2_textfile For Writing As #2
Line Input #1,InputData
Inputdata = "This string will be stored in the text file"
Write #2,InputData
Inputdata = "This will be the second string!"
Write #2,InputData
Close #1
Close #2

!!!If you use this methode, the string shall have " -characters aroud the string. You have to remove them while reading each string.

For fixed data I use ini-files -> faster and better code