|
|||||||
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
#1 |
|
~ Ryan ~
|
VB6 Save and Open
Hello All,
I am working on a VB6 project, and am about to kill myself over this save and open deal. What I want to do is this: - Save the values of many boolean variables, and two integer variables to a text file (.txt) - When clicked open, I want that data to be accessed and the values to be assigned to the variables Here is what is happening : - I am making files and they have the correct contents in them - The files, when opened, are not passing the value of the variables to the variables in the program Here is my save code : Code:
CommonDialog1.DialogTitle = "Save a File"
CommonDialog1.FileName = ""
CommonDialog1.Filter = "Text Files (*.txt)|*.txt|"
CommonDialog1.FilterIndex = 1
CommonDialog1.Flags = cdlOFNHideReadOnly + cdlOFNFileMustExist
CommonDialog1.CancelError = True
CommonDialog1.ShowSave
FileName = CommonDialog1.FileName
Open FileName For Output As 1
' r is games played, wins is how many won, and playedgames in if a game as been played or not to prevent repeating'
Print #1, r
Print #1, wins
For i = 1 To 43
Print #1, playedgames(i)
Next
Close #1
Exit Sub
Here is the code of Opening Code:
CommonDialog1.DialogTitle = "Open a File"
CommonDialog1.FileName = ""
CommonDialog1.Filter = "Text Files (*.txt)|*.txt|"
CommonDialog1.FilterIndex = 1
CommonDialog1.Flags = cdlOFNHideReadOnly + cdlOFNFileMustExist
CommonDialog1.CancelError = True
CommonDialog1.ShowOpen
Open FileName For Input As 1
'Copy entire contents of File to appropriate variables
Input #1, r
Input #1, wins
For i = 1 To 43
Input #1, playedgames(i)
Next
Close 1
Label3.Caption = r
Label5.Caption = wins
- 30 games opened (line one) - 0 games won (line two) - all playedgames booleans set to false because they haven't been completed successfully yet (lines 3 down to line 45, which I wont show) Code:
30 0 False False False False False False False False... Would someone be able to help me figure out how to make it when I open the file that the variables are then updated with the data from the text file. Thanks, Ryan PS - This is the first time I am using this code, and going off a guide my teacher provided... I really am not even sure I am doing it semi-correctly. But, I know the text files are saving, like I said.
__________________
RiotCats.com, an internet domain specifically fabricated and visually erected for the appreciation of the feline kingdom! |
|
|
|
|
|
#2 |
|
Come in Ray...
Join Date: Sep 2004
Posts: 1,668
|
VB doesn't work that way when you are reading. Use a temp variable for your read code:
Code:
Dim blnTemp As Boolean Dim i As Integer i = 0 While Not EOF(1) 'use EOF instead of hard coding passes Input #1, blnTemp playedgames(i) = blnTemp i = i + 1 Wend |
|
|
|
|
|
#3 | |
|
~ Ryan ~
|
Quote:
I have been playing around with it for a while, and I think I got it to work. When I do the input now, it loads the last game, keeps track of wins and everything. All I was missing was one line of code, which I must have forgotten to type in. Those are the kinds of sloppy programming mistakes I make often when trying to get projects done quickly. Here is the open code which is working: Code:
CommonDialog1.DialogTitle = "Open a File"
CommonDialog1.FileName = ""
CommonDialog1.Filter = "Text Files (*.txt)|*.txt|"
CommonDialog1.FilterIndex = 1
CommonDialog1.Flags = cdlOFNHideReadOnly + cdlOFNFileMustExist
CommonDialog1.CancelError = True
CommonDialog1.ShowOpen
FileName = CommonDialog1.FileName
'RichTextBox1.LoadFile CommonDialog1.FileName, rtfRTF
Open FileName For Input As 1
'Copy entire contents of File to appropriate variables
Input #1, r
Input #1, wins
For i = 1 To 43
Input #1, playedgames(i)
Next
Input #1, gamenum
Close #1
gameload 'load the game from gamenum = ...etc...
Label3.Caption = r
Label5.Caption = wins
Code:
for i = 1 to 81 (input/ output) #1, grid(i) next I see how your code is much simpler.. and probably more efficient. I would like to improve my techniques like that... but at the moment, I am content with getting this project up and working. This save and open is just something I wanted to add on to it, so that the program can actually be used by some people, and wasn't a requirement. Last edited by rspassey; 03-17-2006 at 06:16 PM. |
|
|
|
|
|
|
#4 |
|
Come in Ray...
Join Date: Sep 2004
Posts: 1,668
|
That is how it worked in VB4, so I've always done it with a temp variable. The way you are doing it makes more sense though, so don't mind me!
|
|
|
|
|
|
#5 |
|
~ Ryan ~
|
Hmm, everything is working now, but I am running into an issue of it giving the value (true or false) back to the variable, or perhaps I missed something in my coding... Oh well, if I can't figure this one out on my own, then I can just submit the project without this feature, as it isn't required... though I would like to add it in if possible, and I don't have deadlines, so I can play around with it a bit more.
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|