Struct

A structure in nuBASIC is a composite data type consisting of a number elements of other types.
A nuBASIC structure is a value type and the instances of a structure are created in stack.
The keyword struct can be used to declare a structure.
The general form of a structure declaration in nuBASIC is as follows.

Struct <struct_name>
   field1 [as FieldType1]
   field2 [as FieldType2]
   ...
   fieldn [as FieldTypeN]
End Struct

Example:

Struct MyStruct
   x As Integer
   y As String
End Struct

The objects of a struct can be created by using the Dim statement as follows. 

Dim strucvar as MyStruct

The individual members of a struct can be accessed by using the dot (.) operator as showing below.

strucvar.x = 10
strucvar.y = "Hello"

You can use structures in conjunction with arrays. The interactions use the same syntax as these elements use individually.

Example

Struct myStruct
   x(10) as String
   y as Integer
End Struct

Dim s1 as myStruct
Dim s2(2) as myStrct

s1.x(0) = “Hello”
s1.y = 10

s2(0).x(0) = “Hello”
s2(0).x(1) = “World”

s2(1).x(0) = “One”
s2(1).x(1) = “Two”
s2(1).y = 3



Comments