Results 1 to 2 of 2

Thread: Help with structures and files

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2004
    Posts
    20

    Help with structures and files

    Hi, I'm new to VB, this is the first time I use it, so please excuse my ignorance.

    This is what I want to do:

    <filecontent>
    data1moredata1andsomethingelse
    </filecontent>

    I need to open a file in binary mode, then read the first 4 bytes into a variable, the next 9 into another and the 16 left into a 3rd one. I know this is done via structure, declaring 3 variables and the specific length of each other, but, how?

    Can anyone give me an example on how to work around this?

    Thx in advance.

  2. #2

    Thread Starter
    Junior Member
    Join Date
    Jul 2004
    Posts
    20
    Well, as noone replied I'm gonna reply myself with the solution

    <filecontent>
    1234onestringanotherstring
    </filecontenet>

    Code:
    Private Structure Struct1
            Dim iID As Integer
            <VBFixedString(9)> Dim sOne As String
            <VBFixedString(13)> Dim sTwo As String
    End Structure
    
    Public Function Action(ByVal sFilePath As String)
            Dim Struct1 As New Struct1
     
            FileOpen(1, sFilePath, OpenMode.Binary, OpenAccess.Read, OpenShare.LockRead)
            FileGet(1, Struct1)
    
           'more code
          'Struct1.iID is 1234
          'Struct2.sOne is onestring
          'etc
    
    End

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