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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I read from a Text file into VB?

Status
Not open for further replies.

Thadaleus

Technical User
Oct 24, 2000
1
US
I'm new to programming, and I've been able to get all the basics of using MS Access as a database, but I want to use .txt files to set certain variables when the program runs. This seems like the best way, since I'm going to be constantly collecting info from other users which is always changing.
Basically, Access contains the basic info in each record, while the .txt file would list how to use that info.

Remember, I'd consider myself a self-taught beginner. [sig][/sig]
 
You would use the FileSystem object in the Scripting runtime library to open the file.

James :) [sig]<p>James Culshaw<br><a href=mailto:jamesculshaw@active-data-solutions.co.uk>jamesculshaw@active-data-solutions.co.uk</a><br><a href= Active Data Solutions</a><br> [/sig]
 
First, you must have a delimited text file and know its structure. Say you have a text file with several lines of first and last names separated with a comma. You could use the following sub to read the names into an array:

Private Sub Form_Load()
x = 1
Open &quot;path.txt&quot; For Input As #1
Do While Not EOF(1)
Input #1, mstrLname(x), mstrFname(x)
x = x + 1
Loop
Close #1

End Sub

Hope this helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top