Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
10-12-2007, 02:22 AM #1
- Join Date
- Nov 2004
- Perth, UK
- Thanked 0 Times in 0 Posts
Visual Basic 6 - Load from text file
Before I implement a save/load feature into one of my other applications, I created a new program to test it. I put some textboxes, buttons and a couple of checkboxes on the form, and then entered text and used the checkboxes to disable/enable the buttons. Then I pressed my save key. No problems.
The code I used to save was this.
Dim hFile As Long Dim sFilename As String sFilename = CurDir + "\savedata.txt" hFile = FreeFile Open sFilename For Output As #hFile Print #hFile, txtItemOne.Text Print #hFile, txtItemTwo.Text Print #hFile, txtItemThree.Text Print #hFile, Command1.Enabled Print #hFile, Command2.Enabled Print #hFile, Check1.Value Print #hFile, Check2.Value Close #hFile MsgBox "Data Saved. A file called 'savedata.txt' was created.", vbInformation Or vbOKOnly, "Save Data"
The code I use to load is this:
Dim hFile As Long Dim sFilename As String sFilename = CurDir + "\savedata.txt" hFile = FreeFile Open sFilename For Input As #hFile txtItemOne.Text = Input$(LOF(hFile), hFile) txtItemTwo.Text = Input$(LOF(hFile), hFile) txtItemThree.Text = Input$(LOF(hFile), hFile) Command1.Enabled = Input$(LOF(hFile), hFile) Command2.Enabled = Input$(LOF(hFile), hFile) Check1.Enabled = Input$(LOF(hFile), hFile) Check2.Enabled = Input$(LOF(hFile), hFile) Close #hFileGeodesic_D
"I'd much rather be called GeodesicDragon."
10-13-2007, 12:24 AM #2
- Join Date
- Jun 2005
- Near Chicago, IL, USA
- Thanked 32 Times in 31 Posts
I don't code VB6, but in VB.NET and other languages, there are often 2 commands to write to a file. One includes a newline. The other does not.
Have you checked the file contents to see if there are newlines?
If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
Bored? Visit http://www.kaelisspace.com/