Results 1 to 9 of 9

Thread: Text File Handling [Resolved]

  1. #1

    Thread Starter
    Hyperactive Member psycopatchet69's Avatar
    Join Date
    Sep 2004
    Location
    Grand Rapids, MI
    Posts
    256

    Resolved Text File Handling [Resolved]

    Im making a map editor, and i am saving some variables of the collision objects in a text file, and later loading them in the application.

    A few questions, How do i do this? I would have an object array, and i would want to put 5 or so variabled for each object, preferably each objects variables on one line, and then load the line for each object in the app. Any help?
    Last edited by psycopatchet69; Dec 3rd, 2004 at 01:46 AM.

  2. #2
    Fanatic Member
    Join Date
    Sep 2000
    Location
    Over There
    Posts
    522
    simplest way I can think of is to use a tab delimted files

    first thing on line could be object name followed by variable settings.

    if your objects don't have names, but but are just in an array, have the first item be the index array.

    do you know how to write to files??
    if you can post your object description I could probably whip up some code.
    It Never Fails. Everytime I try to make a program idiot proof, the world makes a better idiot.

  3. #3
    Hyperactive Member Disiance's Avatar
    Join Date
    Sep 2004
    Location
    Denver, CO
    Posts
    439
    I would use Binary file operations (Get and Put).
    "I don't want to live alone until I'm married" - M.M.R.P

  4. #4
    Fanatic Member wildcat_2000's Avatar
    Join Date
    Nov 2000
    Location
    Italy
    Posts
    727
    you could think of something like, to save:

    Code:
    Dim iFreeFile As Integer, outFile As String
    Dim mVar(3, 5) As Long, aCount As Long, bCount As Long
    Dim tStr As String
    
    'define vars here
    mVar(1, 1) = 3
    mVar(1, 2) = 45
    mVar(1, 3) = 33
    mVar(1, 4) = 673
    mVar(1, 5) = 2
    mVar(2, 1) = 78
    'etc
    
    'define output file name
    outFile = "mydata.xxx"
    
    iFreeFile = FreeFile
    
    Open App.Path & "\" & outFile For Output As #iFreeFile
    
    For aCount = 1 To 3
        'reset
        tStr = ""
        For bCount = 1 To 5
            tStr = tStr & mVar(aCount, bCount) & Chr(9)
        Next bCount
        'print values
        Print #iFreeFile, tStr
    Next aCount
    
    Close #iFreeFile
    and get back the data in the same way. however, if you do have loads of records i would definitely go the way Disiance suggests: use bytes.
    Last edited by wildcat_2000; Dec 3rd, 2004 at 05:52 AM.
    When your car breaks down,
    close all windows and retry

    => please rate all users posts! <=

  5. #5

    Thread Starter
    Hyperactive Member psycopatchet69's Avatar
    Join Date
    Sep 2004
    Location
    Grand Rapids, MI
    Posts
    256

    Re: Text File Handling

    No, i do not know how to read or write from files, which is my main purpose of this thread, i should have stated that.


    Alright, ill explain my problem a little more clearly.
    I made a map editor for my rpg, and it saves the map as one single .bmp
    The editor also includes a collision maker, which adds the collisions on the maps, and i want them printed into a text file.

    I want the textbox to have all the data for one collision object in one line.

    For example:

    the first line of the text file i want to have the number of collobjts and thats it

    with collobjt(0)
    .left = 16
    .top = 16
    .width = 48
    .height = 32
    end with

    i want this data above to be in the 2nd line of the text file as follows

    index,left,top,width,height
    0,16,16,48,32

    So the text file with 1 collobjt would be as follows

    0
    0,16,16,48,32

    With 2 collobjts

    1
    0,16,16,48,32
    1,32,48,48,32


    I also need to know how to read these files

    I hope that explains what i am looking for. Please help...Soon, i am done coding the editor except for this part, so i cant use it for my game until i figure this out.


    If someone could make me a simple example where it saves and loads the data from textboxes into this format, i would appreciate it.

  6. #6

    Thread Starter
    Hyperactive Member psycopatchet69's Avatar
    Join Date
    Sep 2004
    Location
    Grand Rapids, MI
    Posts
    256

    Re: Text File Handling

    Anyone?

  7. #7
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Text File Handling

    Code:
    Sub WriteFile()
      outFile = "mydata.xxx"
      iFreeFile = FreeFile
      Open App.Path & "\" & outFile For Output As #iFreeFile
      print #iFreeFile, UBound(collobjt)
      For x = 0 To UBound(collobjt)
        with collobjt(x)
          print #iFreeFile, .left, .top, .width, .height
        End with
      Next x
      Close #iFreeFile
    End Sub
    
    Sub ReadFile()
      Dim colobj  ', a,b,c,d
      outFile = "mydata.xxx"
      iFreeFile = FreeFile
      Open App.Path & "\" & outFile For Input As #iFreeFile
      read #iFreeFile, colobj
      Dim collobjt(colobj)
      For x = 0 To UBound(collobjt)
        with collobjt(x)
          read #iFreeFile, .left, .top, .width, .height
    ' You may Not be able To read directly into properties. Might have To use 
    '      read #iFreeFile, a,b,c,d
    '         .left = a
    '         .top = b
    '         .width = c
    '         .height = d
       End with
      Next x
      Close #iFreeFile
    End Sub

  8. #8

    Thread Starter
    Hyperactive Member psycopatchet69's Avatar
    Join Date
    Sep 2004
    Location
    Grand Rapids, MI
    Posts
    256

    Re: Text File Handling

    Thank you very much, i think this is doing the trick, the writefile works perfect, but the readfile i dont really understand.... And i dont think that the "Read #ifreefile" is the right function, because the line is displayed in red in vb....
    Last edited by psycopatchet69; Dec 3rd, 2004 at 01:27 AM.

  9. #9

    Thread Starter
    Hyperactive Member psycopatchet69's Avatar
    Join Date
    Sep 2004
    Location
    Grand Rapids, MI
    Posts
    256

    Re: Text File Handling

    Nevermind, i figured it out, the correct term was "Input" not "Read".

    I thank you very much for helping me with my code.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width