[Gambas-user] gb3: using array of structures with dimensions unknown until runtime
Kevin Fishburne
kevinfishburne at ...1887...
Wed Jul 4 06:31:43 CEST 2012
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
More information about the User
mailing list