Tools Links Login

Aa Tutorial on Saving: How to do it!

This code will teach a user how to save their data and also how to retrieve it. Very easy to understand if you read the ' comments. :) Enjoy!

Original Author: Dound

Assumptions

Just read the code/comments and be prepared to learn!

Code

Dim strTest As String
Private Sub Command1_Click()
FileNum = FreeFile() 'Finds a freefile where it can write to
Open App.Path & "Test.test" For Input As FileNum 'opens the file to (input = get data)
Input #FileNum, strTest 'Get data by putting Input then the FileNumber you opened in (we used a variable FileNum) then a comma then the variable you want to store.
Close FileNum 'Close the FileNumber you opened...'Close' by itself will close ALL of your open files.
Text1.Text = strTest 'sets the textbox's text = to what was is the file
End Sub
Private Sub Command2_Click()
FileNum = FreeFile()
Open App.Path & "Test.test" For Output As FileNum 'Output clears the file and gives you access to write to it with the Write command
Write #FileNum, strTest 'Write then #FileNumber (we used a variable) then a comma then the variable you want to save
Close FileNum 'You can save multiple variables at once if you seperate them by commas
End Sub
Private Sub Command3_Click()
Kill App.Path & "Test.test"
'Deletes File "Test.test" at the application's path
End Sub
Private Sub Text1_Change()
strTest = Text1.Text 'puts text in the string whenever the textbox's text changes
End Sub
'End of code...
'The easiest way to write multiple values to a file is like this:
'Write #FileNum, strTest, strTest2, strTest3
'...just keep adding commas and then the next vaule to save
'Be sure to load EVERYTHING you saved and in the same order you saved it! or it wont work!!
'A shortcut for saving arrays:
'For Q = 1 To 5: Write #NFile, Array(Q):Next
'...and so on...Enjoy!

About this post

Posted: 2002-06-01
By: ArchiveBot
Viewed: 89 times

Categories

Visual Basic 6

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.