Visual Basic Explorer
Visual Basic Explorer
 Navigation
 Home


 Coding
 Source Code

 FAQ Center

 VB Tips

 Downloads

 ToolBox

 Tutorials

 VB Games

 VB News

 VB Award

 VB Forums



 Affiliates
 Planet Source Code

 Rent a Coder

 DirectX4VB


 Misc
 Search

 Feedback

 Advertise

 About


Need to hire
a VB coder?

Please support our sponsor:

 Home 
 Site Map 
 Forums 
 News 
 Feedback 

 

'------------------------------------------------------
'How To: Save Data to a Text File
'Posted: June 1998
'From: "Robert L. Walsh" rlwalsh@capecod.net
'------------------------------------------------------
Keywords to see in on-line help: Open, Print #, Close, FreeFile,
Input #, Line Input #, EOF(), LOF().

 
Text files are stored in sequential files, that is, files that must
always be read from the beginning to the end or to some point
before the end. It goes without saying that the files are also
written to disk from beginning to end.

 
'Writing to the file:

 
Dim iFB As Integer

 
iFB = FreeFile 'Get next available file buffer.
Open "C:\MyDir\MyFile" For Output As #iFB 'Open the file to write to disk.
Print #iFB, Text1.Text 'Write out contents of some textbox.
Close iFB 'Close the file buffer.

 
'Reading from the File:

Dim iFB As Integer, sTmp1 As String, sTmp2 As String

 
iFb = FreeFile
Open "C:\MyDir\MyFile" For Input As #iFB 'Open for read (input).
Do While EOF(iFB) = False 'Loop thru multiple lines.
Line Input #iFB, sTmp1 'Input a whole line or row.
sTmp2 = sTmp2 & sTmp1 & vbCrLf 'Append to sTmp2 with crlf.
Loop
Text1.Temp = sTmp2
Close iFB

 
The code to read the file includes a loop to allow reading in multiple
lines. Multiple lines can, of course, be written as well. Code to do
that has been omitted here for simplicity`s sake. The VB constant
vbCrLf supplies a pair of characters known as a Carriage Return,
Line Feed. They are, in fact, the Ascii characters 13 and 10.

 


Downloads

In IE right-click and select 'Save Target As...' or in Netscape right-click and select 'Save Link As...'

 

View Plain Text View Plain Text
Download Demo Project Not Available
View Code Online Not Available





Home | About | What's New | Source Code | FAQ | Tips & Tricks | Downloads | ToolBox | Tutorials | Game Programming | VB Award | Search | VB Forums | Feedback | VBNews | Copyright & Disclaimer | Advertise | Privacy Policy |

Quick searches: Site Search | Advanced Site Search 

Copyright 2002 by Exhedra Solutions, Inc.
By using this site you agree to its terms and conditions
VB Explorer and VBExplorer.com are trademarks of Exhedra Solutions, Inc.