VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Aa Tutorial on Saving: How to do it

by Dound (7 Submissions)
Category: Databases/Data Access/DAO/ADO
Compatability: Visual Basic 3.0
Difficulty: Intermediate
Date Added: Wed 3rd February 2021
Rating: (9 Votes)

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!

Assumes
Just read the code/comments and be prepared to learn!
Code Returns
Nothing
API Declarations
None.

Rate Aa Tutorial on Saving: How to do it

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!

Download this snippet    Add to My Saved Code

Aa Tutorial on Saving: How to do it Comments

No comments have been posted about Aa Tutorial on Saving: How to do it. Why not be the first to post a comment about Aa Tutorial on Saving: How to do it.

Post your comment

Subject:
Message:
0/1000 characters