Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Input/Output to a text file

Status
Not open for further replies.

jamesleong

Programmer
Jan 29, 2003
22
0
0
MU
Hi everyone,
I need to write and to read many lines from a text file, my program will make use of an array of records. each entry in the array will represent a record. can anyone help me with these two procedures (reading /writing)? Can anyone give me a sample? Am reading from msdn, it reads from a file at one go!!

thanking you in advance for your help.

james.
 
Hi,

With regard to reading the text file line by line:

Code:
Dim strInput as String

Dim strNotepad as String
[green]'strNotepad is the path to the file you want to read from[/green]

Open strNotepad For Input As #1
While Not EOF(1)
[green]'reads the current line into a string, instead of the string you could read it into your array[/green]
Line Input #1, strInput
Wend
Close #1

Hope this helps on the first part at least

Harleyquinn

---------------------------------
For tsunami relief donations
 
If the file's not REALLY big, you can read it all in at once and then Split() it into an array on the vbNewLine character. That's faster than a bunch of disk reads, though I found with an array of more than 100,000 elements, it's faster with VB to read the individual lines.

Lee
 
Hi,
Thanks trollacious, i am learning VB now, was on foxpro 2.6 previously, its a bit hard for me to search for the different functions, so if you already have the procedures to write and read from text file, it would greatly help me..thanking you in advance.

James.
 
The following will read an entire text file and split it into an array with one line in each element.

Code:
Dim filename As String, filestring As String
Dim arrRecords() As String

Open filename For Binary As #1
filestring = Input(LOF(1), 1)
Close #1

arrRecords = Split(filestring, vbNewLine)

When you have the VB IDE open, put your mouse cursor on the word Open and press the F1 key to get help on different ways to open files for reading and writing.

Lee
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top