Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hello all,
How do i store some records inputed by me in a visual basic program in a file and then retreive them using the same file?If you could give me a link to any website which teached you that i would be very greatful to you.Thanx in advance for all your help
ROCKO

It amazes me that you have to ask this question because I think the VB help file has some great examples...but obviously you are not the only one who cannot find this in the help file since I have already answered a question very similar to this one...look back in the threads or search for FreeFile()...or if you are lazy (like me) then:
Sub LoadSomeFile()
Dim FP as Long ' File Handle
Dim FileSpec as String ' File Name
Dim FileBody as String ' The Contents Of The FileFileSpec = App.Path & "\somefile.dat" ' app.path is the current application path, until you compile it i think vb6 makes the app.path c:\program files\microsoft visual studio\vb98\ but i could be wrong in that assumption.
FP = FreeFile() ' this asks the system for the next available file number (handle)
Open FileSpec For Input As #FP ' open it for read
FileBody = Input(EOF(fp),#FP) ' read the entire file into the filebody variable
Close #fp
' Do something with FileBody (parse it, display it, whatever)
End SubSub SaveSomeFile(ByVal FileBody as String)
Dim FP as Long ' File Handle
Dim FileSpec as String ' File NameFileSpec = App.Path & "\somefile.dat"
FP = FreeFile() ' this asks the system for the next available file number (handle)
Open FileSpec For Output As #FP ' open it for write
print #FP, FileBody ' write the entire file
Close #fp
End SubSub AppendSomeFile(byval FileData As String)
Dim FP as Long ' File Handle
Dim FileSpec as String ' File NameFileSpec = App.Path & "\somefile.dat"
FP = FreeFile() ' this asks the system for the next available file number (handle)
Open FileSpec For Append As #FP ' open it for write
line print #FP, FileData ' write a line
Close #fp
End Sub
Have fun,
Chi Happens

![]() |
read a File to aMatrix in...
|
basic calculater
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |