[Gambas-user] gb3: using array of structures with dimensions unknown until runtime

Emil Lenngren emil.lenngren at ...626...
Wed Jul 4 11:42:17 CEST 2012


When you are declaring the array by writing
A[3] As Single
you declare an inline array, i.e. NOT a reference to an array.
So you cannot write
ThatStruct.A = AnArray.
Instead you have to copy the contents from AnArray into A.

2012/7/4 Kevin Fishburne <kevinfishburne at ...1887...>

> On 07/04/2012 12:06 AM, Kevin Fishburne wrote:
> > I need to create a 2D array of a structure like this:
> >
> > Public Struct Tile_Normals
> >     A[3] As Single  ' Normal for quad subsurface A.
> >     B[3] As Single  ' Normal for quad subsurface B.
> > End Struct
> >
> > Dim Normals As New Tile_Normals[TileGrid.Size, TileGrid.Size]
> >
> > When I try to assign a value to an array element like this:
> >
> > Normals[TileGridX, TileGridY].A = Convert.Normal(P1, P2, P3)
> >
> > I get a "null object" error. While the 2D array of structures seems to
> > be created correctly, all its initial values are indeed "null". Do I
> > need to create the structure or array differently so I can properly
> > assign values to it?
> >
> > Previously I knew all the dimensions of my arrays of structures so they
> > were statically defined, but in this case I don't know the array
> > dimensions until after the program has started running. Thanks everyone.
> >
>
> One addition. I've discovered that if I publicly declare a 2D array of
> the structure it shows "bad number of dimensions" and "out of bounds"
> errors when I double-click it after creation:
>
> ' Tile grid normal structure.
> Public Struct Tile_Normals
>    A As Single[]  ' Normal for quad subsurface A.
>    B As Single[]  ' Normal for quad subsurface B.
> End Struct
> Public Normals[32, 32] As Struct Tile_Normals
>
> Declaring it as a 1D array it behaves normally:
>
> ' Tile grid normal structure.
> Public Struct Tile_Normals
>    A As Single[]  ' Normal for quad subsurface A.
>    B As Single[]  ' Normal for quad subsurface B.
> End Struct
> Public Normals[32] As Struct Tile_Normals
>
> It also doesn't make any difference if I define the structure like this:
>
> ' Tile grid normal structure.
> Public Struct Tile_Normals
>    A[3] As Single  ' Normal for quad subsurface A.
>    B[3] As Single  ' Normal for quad subsurface B.
> End Struct
>
> Maybe that's related to what's happening, or a separate issue?
>
> --
> Kevin Fishburne
> Eight Virtues
> www: http://sales.eightvirtues.com
> e-mail: sales at ...1887...
> phone: (770) 853-6271
>
>
>
> ------------------------------------------------------------------------------
> Live Security Virtual Conference
> Exclusive live event will cover all the ways today's security and
> threat landscape has changed and how IT managers can respond. Discussions
> will include endpoint security, mobile security and the latest in malware
> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>



More information about the User mailing list