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

text file

Status
Not open for further replies.

tanker0016

Programmer
Mar 17, 2003
6
US
How do I create, save, open, and retrieve information from a text file.


Tanker0016
 
Use FileSystemObject
Make sure to include microsoft scripting runtime reference in your project. Good Luck
 
or search msdn (or this forum) for "open statement"

good luck!

If somethings hard to do, its not worth doing - Homer Simpson
------------------------------------------------------------------------
A General Guide To Excel in VB FAQ222-3383
 
There are many variations on this and you need to look up a reference for more detail but to get you started:-

To open a file for writing use:
Open "MyFileName.txt" for OUTPUT as #1 (or) Open "MyFileName.txt" for APPEND as #1
Print #1, "MyText"
Close #1

'Output will create a new file, overwriting an existing file if it exists.
'Append will create a new file or add to an existing one.

To open a file for reading use:
Open "MyFileName.txt" for INPUT as #1
Do While Not EOF(1)
Input #1, MyText (or) Line Input #1, MyText
List1.AddItem MyText '(Display the contents of the file in a listbox, textbox or whatever you prefer)
Loop
Close #1

'Use Line Input if MyText includes any punctuation marks otherwise you will only Input text up to the first punctuation.

Good Luck
 
If i were to have about 23 text boxes and 3 drop down boxes how would i save them under 1 file and not write over that data, but add on to it..... And each text box is going to display a part of this.... basically what the program is a program that stores information for a set a tires like pressure and temperature....

thx

Tanker0016


 
Use the Append version that bigalbigal has given you, and loop round the textboxes.

To loop, look up [tt]For Each...Next[/tt] and [tt]Typeof[/tt]


________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top