Array indices

S

Scott Townsend

So here is a noob question..

I'm looking to have
Int16
SQLCmd Byte Array that is a Total of 256 Bytes
PARMS Byte Array that is a Total of 1080Bytes
UNUSED Byte Array that is a Total of 708Bytes

This this what I want?
<StructLayout(LayoutKind.Explicit, CharSet:=CharSet.Ansi, Pack:=1,
Size:=2048)> _
Structure SQL_COMMAND
<FieldOffset(0)> Dim PLC_Type As Int16
<FieldOffset(4), VBFixedArray(256)> Dim SQLCmd As Byte()
<FieldOffset(260), VBFixedArray(1080)> Dim PARMS As Byte()
<FieldOffset(1340), VBFixedArray(708)> Dim UNUSED As Byte()
End Structure


Or do I have to decrement the indexes By 1??
<StructLayout(LayoutKind.Explicit, CharSet:=CharSet.Ansi, Pack:=1,
Size:=2048)> _
Structure SQL_COMMAND
<FieldOffset(0)> Dim PLC_Type As Int16
<FieldOffset(4), VBFixedArray(255)> Dim SQLCmd As Byte()
<FieldOffset(260), VBFixedArray(1079)> Dim PARMS As Byte()
<FieldOffset(1340), VBFixedArray(707)> Dim UNUSED As Byte()
End Structure
 
D

David Anton

You have to decrement by 1 since VB specifies the upper bound in the array
size specifier (unlike every other language which specifies the length ...).
--
http://www.tangiblesoftwaresolutions.com
C++ to C#
C++ to VB
C++ to Java
VB to Java
Java to VB & C#
Instant C#: VB to C#
Instant VB: C# to VB
Instant C++: VB, C#, or Java to C++/CLI
 
G

Göran Andersson

Scott said:
So here is a noob question..

I'm looking to have
Int16
SQLCmd Byte Array that is a Total of 256 Bytes
PARMS Byte Array that is a Total of 1080Bytes
UNUSED Byte Array that is a Total of 708Bytes

This this what I want?
<StructLayout(LayoutKind.Explicit, CharSet:=CharSet.Ansi, Pack:=1,
Size:=2048)> _
Structure SQL_COMMAND
<FieldOffset(0)> Dim PLC_Type As Int16
<FieldOffset(4), VBFixedArray(256)> Dim SQLCmd As Byte()
<FieldOffset(260), VBFixedArray(1080)> Dim PARMS As Byte()
<FieldOffset(1340), VBFixedArray(708)> Dim UNUSED As Byte()
End Structure


Or do I have to decrement the indexes By 1??
<StructLayout(LayoutKind.Explicit, CharSet:=CharSet.Ansi, Pack:=1,
Size:=2048)> _
Structure SQL_COMMAND
<FieldOffset(0)> Dim PLC_Type As Int16
<FieldOffset(4), VBFixedArray(255)> Dim SQLCmd As Byte()
<FieldOffset(260), VBFixedArray(1079)> Dim PARMS As Byte()
<FieldOffset(1340), VBFixedArray(707)> Dim UNUSED As Byte()
End Structure

The constructor of the VBFixedArrayAttribute takes the upper bound of
the array, so you have to use a value one less than the size.

However, the VBFixedArrayAttribute does not change how the data is
stored in the structure, the way that StructLayoutAttribute does. To use
it with marsalling, you might want to use something like this instead:

<MarshalAs(UnmanagedType.ByValArray, SizeConst:=256)>
 
S

Scott Townsend

Maybe I should have gone to be early and then read your message and not
banged my head for so long... (-;

What happened to the Old Days where you could use the memory the way you
wanted to.. (-;

Thanks!
 
C

Cor Ligthert[MVP]

Scott,

How long is that ago?

The last time I could use memory in a computer the way I wanted to, the
computer had no OS or whatever control system at all. (I never used things
like commodore 64, so I don't know how that was).

Cor

Scott Townsend said:
Maybe I should have gone to be early and then read your message and not
banged my head for so long... (-;

What happened to the Old Days where you could use the memory the way you
wanted to.. (-;

Thanks!
 
S

Scott Townsend

As long as you had a handle to a memory structure you could (type) it as
anything you wanted to.
ol' Microsoft C and MASM. A bit o ThinkC on the Mac...

Not as easy in Pascal. Now on a C64, that's where there was nothing a good
Peek/Poke couldn't Fix! (-:

Scott<-

Cor Ligthert said:
Scott,

How long is that ago?

The last time I could use memory in a computer the way I wanted to, the
computer had no OS or whatever control system at all. (I never used things
like commodore 64, so I don't know how that was).

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top