Sign in to follow this  
Kryptus

Structure Problem

Recommended Posts

Kryptus    100
Alright now, I am currently using Visual Basic 6 to load the beginning of a file into a structure (or Type as it's called in VB). I'll give you a sample of what I am trying to do below: This would be the contents of a make believe file: FILE1026This is a sample file!.txt6055 The type is as follows:
Public Type Header
    Signature As String * 4
    Version As Integer
    FileNameLength As Integer
    FileName As String
End Type

Public myHeader As Header

This is then loaded using the simple Get command:
    Dim FileNum As Integer
    FileNum = FreeFile

    Open FileIAmGonnaUse For Binary As FreeFile
        Get FileNum, , myHeader
    Close FreeFile

The problem is, I don't know how to tell the header what the file name length is. On that sample file I wrote at the top, there is a 6055 at the end and currently the FileName string contains that. What I am trying to achieve is what you see below:
Public Type Header
    Signature As String * 4
    Version As Integer
    FileNameLength As Integer
    FileName As String * FileName Length ' <<<<----- But here you can't do this but you get the picture I hope
End Type

Public myHeader As Header

Share this post


Link to post
Share on other sites
Fil    168
If you want to read your header in a single instruction, you have to decide the max file length you can have (for example 256).
So you can change your header this way:


Public Type Header
Signature As String * 4
Version As Integer
FileNameLength As Integer
FileName As String * 256 '<-- changed!
End Type



You will read 256 char for FileName but you know you have to consider the first 'FileNameLength' bytes.

Hope that helps.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this