Computing.Net > Forums > Programming > visual basic

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

visual basic

Reply to Message Icon

Name: nsrd_in
Date: July 29, 2003 at 03:13:11 Pacific
OS: Windows XP Pro/Redhat Lin
CPU/Ram: (933 Mhz-Intel 810E-384 M
Comment:

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



Sponsored Link
Ads by Google

Response Number 1
Name: Chi Happens
Date: July 29, 2003 at 07:08:07 Pacific
Reply:

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 File

FileSpec = 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 Sub

Sub SaveSomeFile(ByVal FileBody as String)
Dim FP as Long ' File Handle
Dim FileSpec as String ' File Name

FileSpec = 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 Sub

Sub AppendSomeFile(byval FileData As String)
Dim FP as Long ' File Handle
Dim FileSpec as String ' File Name

FileSpec = 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


0
Reply to Message Icon

Related Posts

See More


read a File to aMatrix in... basic calculater



Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: visual basic

List Databses is Visual Basic 6 www.computing.net/answers/programming/list-databses-is-visual-basic-6/15612.html

visual basic and C# www.computing.net/answers/programming/visual-basic-and-c/1113.html

visual basic www.computing.net/answers/programming/visual-basic/9625.html