Results 1 to 3 of 3

Thread: Writing to Files

  1. #1

    Thread Starter
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134

    Red face

    I know this sounds kinda boring, but.... In you're opinion, what is the best way to read/write?

    I'm using:

    Code:
    Sub LoadFile(sFileName as String)
    Dim Temp as String
    Open App.Path & "\vector\" & sFileName For Input As #1
       Input #1, Temp
    Close #1
    End Sub
    Anyway, you get the Idea. So, how would I maximize my code If I wanted to Read/Write the Data From a User-Defined Type?

    This is what it's probably going to be:
    Code:
    Option Explicit
    
    Public Enum vgfNodeType
       vgfLine = 0
       vgfPolyLine = 1
       vgfFilledPoly = 2
       vgfInline = 3
    End Enum
    
    Public Type RGBInfo
       R As Single
       G As Single
       B As Single
    End Type
    
    Public Type Node
       NodeType as vgfNodeType
       FilledColour As RGBInfo
       LineColour As RGBInfo
       LineStart() As POINTAPI
       LineEnd() As POINTAPI
       AntiAliased As Boolean
    End Type
    (by the way, I have POINTAPI defined as well)

    So, my question is, what would be the best method for writing and reading the Node UDT?
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    If you open in binary, it's quite easy to store UDT's, but if you have dynamic arrays you should store the size of them too:
    Code:
        Dim n As Node, LS As Integer, LE As Integer 'or byte if you have a arrays smaller than 256
        'Loading UDT
        ff = FreeFile
        Open file For Binary As ff
            Get #ff, , LS
            Get #ff, , LE
            ReDim n.LineStart(LS)
            ReDim n.LineEnd(LE)
            Get #ff, , n
        Close ff
    
        'Saving UDT
        ff = FreeFile
        Open file For Binary As ff
            LS = UBound(n.LineStart)
            LE = UBound(n.LineEnd)
            Put #ff, , LS
            Put #ff, , LE
            Put #ff, , n
        Close ff
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3

    Thread Starter
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134

    Thumbs up

    Looks good! I'll try it.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

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