Array in structure

  • Thread starter Thread starter David Scemama
  • Start date Start date
D

David Scemama

Hi,

I need to read fixed length records from a file. The record contains a fixed
sized table of another structure (let's say 100 elements).

I use the fileGet method to read the records with a structure.

The first problem I have is that I did not manage to define a fixed sized
array in the structure
structure Rec1
public tab as Rec2(100) 'Rec2 is another structure
end Structure
is not a valid syntax

I've then tried to do the following :
Structure Rec1
<VBFixedString(100*sizeofRec2)> tab as string
End Structure
in this case, I can read Rec1 correctly, but I can't figure out how to
extract the elements of type Rec2 in tab

Thanks for your help
David
 
You should be able to use the VBFixedArray for that:

Module Module1

Structure s1
<VBFixedArray(99)> Public arr() As s2
End Structure

Structure s2
Public i As Integer
End Structure

Sub Main()
Dim s1, s2 As s1
ReDim s1.arr(99)
ReDim s2.arr(99)
s1.arr(5).i = 42
FileOpen(1, "t.txt", OpenMode.Binary)
FilePut(1, s1)
FileClose(1)


FileOpen(1, "t.txt", OpenMode.Binary)
FileGet(1, s2)
FileClose(1)

Console.WriteLine(s2.arr(5).i)
End Sub

End Module

this will output and read back a structure containing an array of 100
structures

Hope that helps,
Alex
 
Back
Top