questions about saving/loading multiple variables from .txt file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mrnn
    New Member
    • Sep 2007
    • 29

    questions about saving/loading multiple variables from .txt file

    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?
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    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.

    Comment

    • mrnn
      New Member
      • Sep 2007
      • 29

      #3
      Originally posted by Killer42
      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.

      [CODE=vb] Open App.Path & "\" & strName & ".txt" for Output As #1
      Dim a as String
      Dim b, c(29), i As Integer
      a = strName ' [player's name]
      b = intDiff ' [difficulty level]
      For i = 0 To 29
      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]
      Next
      Close #1[/CODE]

      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.

      Comment

      • Killer42
        Recognized Expert Expert
        • Oct 2006
        • 8429

        #4
        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.

        Comment

        • mrnn
          New Member
          • Sep 2007
          • 29

          #5
          Originally posted by Killer42
          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:
          [CODE=vb]write #1, a
          write #1, b
          for i = (0 to 29)
          write #1, c(i)

          Close #1[/CODE]

          Comment

          • mrnn
            New Member
            • Sep 2007
            • 29

            #6
            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?

            Comment

            • Killer42
              Recognized Expert Expert
              • Oct 2006
              • 8429

              #7
              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.

              Comment

              • mrnn
                New Member
                • Sep 2007
                • 29

                #8
                Originally posted by Killer42
                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
                Last edited by mrnn; Oct 1 '07, 10:13 PM. Reason: forgot somethin quick

                Comment

                Working...