Advertisement
2002C Databases/ Data Access/ DAO/ ADO #12133

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!

AI

AI 요약: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

소스 코드
original-source
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!
원본 댓글 (3)
Wayback Machine에서 복구됨