By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,021 Members | 952 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,021 IT Pros & Developers. It's quick & easy.

questions about saving/loading multiple variables from .txt file

mrnn
P: 29
Ok I know how to save and load 1 variable from a file, but when it comes to loading multiple variables, I get confused. And all the articles I've found using Google and on here haven't helped too much.

For example I want to save the player's name (strName), which level they're on (intLevel), and which cheats are available (bolCheats(9), a true-false array). Please help me out.

Also it saves the file to (app.path & "\levels\" & strName & ".txt") and when it loads it opens to the folder (app.path & "\levels") then you select the file from a basic file seeker application which I can make myself.

Also I promise this is the last question I'll ask for a long while :P this is the last thing I don't know/remember and need to know for my game, just please help me out with this final question?
Sep 23 '07 #1
Share this Question
Share on Google+
7 Replies


Expert 5K+
P: 8,434
What version of VB are you using? And what technique are you using to save/retrieve your single variable? It's probably simplest if we just build on that.
Sep 24 '07 #2

mrnn
P: 29
What version of VB are you using? And what technique are you using to save/retrieve your single variable? It's probably simplest if we just build on that.
Using VB6 (as usual :P) and I'm not saving/retrieving a single variable, it's multiple. There will be more but if I know how to save/read 3 it shouldn't be a problem to put more on.

Expand|Select|Wrap|Line Numbers
  1.  Open App.Path & "\" & strName & ".txt" for Output As #1
  2. Dim a as String
  3. Dim b, c(29), i As Integer
  4. a = strName     ' [player's name]
  5. b = intDiff     ' [difficulty level]
  6. For i = 0 To 29 
  7.     c(i) = ifBeat(i) ' [Variable that keeps track if you beat a level or not, and the levels arent in linear order (you can choose which to go to) hence the array]
  8. Next
  9. Close #1
I think that's how the saving works, but I don't 100% remember and at the moment I'm not at my home computer so I can't test it either.
Sep 24 '07 #3

Expert 5K+
P: 8,434
As far as I can see, that doesn't save anything anywhere. It just opens the file, puts values in an array of Variant-type variables, then closes the file.
Sep 24 '07 #4

mrnn
P: 29
As far as I can see, that doesn't save anything anywhere. It just opens the file, puts values in an array of Variant-type variables, then closes the file.
Oops I forgot some stuff, sorry. Forgot to put:
Expand|Select|Wrap|Line Numbers
  1. write #1, a
  2. write #1, b
  3. for i = (0 to 29)
  4.      write #1, c(i)
  5.  
  6. Close #1
Sep 25 '07 #5

mrnn
P: 29
aww nobody's gonna help me? :P

...unless i'm stupid and its somethin simple like Read #1, a or somethin like that...but please i dont remember how to load multiple variables from a file

and sorry i dont have access to my usual computer (the one with vb6) so i cant test it out at the moment, but please help refresh my memory?
Oct 1 '07 #6

Expert 5K+
P: 8,434
I think what it boils down to is that if you can store and load one item of data, you can repeat the same thing as many times as you like for multiple items. If you want to save multiple items on a line, then I believe the Input # statement can handle reading them. You would write them using either Write # or Print #, I forget which. It's all in the documentation.
Oct 1 '07 #7

mrnn
P: 29
I think what it boils down to is that if you can store and load one item of data, you can repeat the same thing as many times as you like for multiple items. If you want to save multiple items on a line, then I believe the Input # statement can handle reading them. You would write them using either Write # or Print #, I forget which. It's all in the documentation.
yeah ur probably right...i'll make sure to try it out when i can...i've been readin through the huge manual i have and lookin around on google...

anyways sorry for bein stupid :P ...and thanks for helpin
Oct 1 '07 #8

Post your reply

Sign in to post your reply or Sign up for a free account.