VB icon

Aa Tutorial on Saving: How to do it!

Email
Submitted on: 1/8/2015 2:43:00 AM
By: Dound (from psc cd)  
Level: Intermediate
User Rating: By 9 Users
Compatibility: VB 5.0, VB 6.0
Views: 670
 
     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!
 

Windows API/Global Declarations:

Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
'**************************************
'Windows API/Global Declarations for :Aa Tutorial on Saving: How to do it!
'**************************************
None.
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
'**************************************
' Name: Aa Tutorial on Saving: How to do it!
' Description: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!
' By: Dound (from psc cd)
'
' Returns:Nothing
'
' Assumes:Just read the code/comments and be prepared to learn!
'**************************************

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!


Other 6 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.