Understanding UDT format

future56k
08-17-2009, 07:06 PM
Hello,

I want to store a UDT in an eeprom and retrieve it later. Also I want to have a microcontroller doing some things with the data.

I've created a test case:

Private Type Teste
aa As Byte
P() As Integer
V() As Integer
End Type

t.aa = 10
ReDim t.P(t.aa)
ReDim t.V(t.aa)
Dim ccc As Byte
For ccc = 0 To t.aa - 1
t.P(ccc) = ccc
t.V(ccc) = ccc + 100
Next
ccc = FreeFile()
Open "test.dat" For Random As #ccc
Put #ccc, , t
Close #ccc

test.dat contents:
0A
01000B000000000000
0000000100020003000400050006000700080009000000
01000B000000000000
006400650066006700680069006A006B006C006D000000

I've separated the hex numbers in a way that looks right to me.. 1st, 3rd and 5th lines seem to be data. I don't imagine what could be lines 2 and 4.

Can anyone point me to the right direction?

Thank you.

Rockoon
08-17-2009, 07:59 PM
Lines 2 and 4 hold descriptions of the arrays

1-dimentional, and 11 elements.

future56k
08-18-2009, 06:27 AM
Yes, but lines 2 and 4 have a lot of meaningless zeros!? Or it has 8 bytes for array size?

Rockoon
08-18-2009, 06:54 AM
well, the base of the array is probably also stored .. try dimensioning the arrays (1 to 11) instead of (0 to 10) ..

I no longer have VB6 handy in order to do a more complete investigation myself...

The base is probably only a 16-bit value, and then there is either a padding/reserved byte or perhaps there is yet another feature that I am not accounting for.

kassyopeia
08-18-2009, 07:08 AM
More comprehensive test:
ReDim ...(11 To 12, 21 To 23, 31 To 34)
03 00 04 00 00 00 1F 00 00 00 03 00 00 00 15 00 00 00 02 00 00 00 0B 00 00 00
Looks like int dims, {long size, long lbound}, in inverse indexing order.

Rockoon
08-18-2009, 07:53 AM
If thats the case, then we find that the reporting of his test.dat is misaligning the "lines" .. the first bytes of lines 3 and 5 should be at the end of 2 and 4, respectively:

0A
0100|0B000000|00000000
0000|0100|0200|0300|0400|0500|0600|0700|0800|0900|0000
0100|0B000000|00000000
6400|6500|6600|6700|6800|6900|6A00|6B00|6C00|6D00|0000

Note that Intel's are Little Endian, the Least Significant Byte comes first.

and now all is right with the world :) there are no other "feature bits"

16-bit Dimensions
32-bit size
32-bit base

kassyopeia
08-18-2009, 08:11 AM
Epilog (http://msdn.microsoft.com/en-us/library/ms221167.aspx):

typedef struct tagSAFEARRAYBOUND {
unsigned long cElements;
long lLbound;
} SAFEARRAYBOUND;

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum