Please enable JavaScript to view this site.

thinBasic Help Manual

* * HELP & MANUAL PREMIUM PACK 4 DEMO VERSION * *

This documentation was styled with a demo skin from the Premium Pack 4 add-on for Help & Manual. The contents of the skin are encrypted and not configurable. You can only publish HM projects with this skin. You cannot edit it or change it.

This version is copyright and may only be used for local testing purposes. It may not be distributed.

Please purchase the full version of the Premium Pack to get the configurable skins and remove this notice. The package will also include the Toolbox configuration utility for Premium Pack skins.

 

Elements

 

As the previous chapter mentioned, you need to specify at least one element for user defined type.

 

Syntax

 

[STATIC] elementName[(numberOfDimensions)] AS elementType [= value]

 

Element definition has two mandatory parts:

1.elementName, following the same naming rules as any other variable

2.elementType, which can be any numeric, string or user defined type

 

Element can be also an array, in such a case you specify number of items in the brackets after the elementName:

 

TYPE Triangle

  point(3) AS Point2D

END TYPE

 

DIM t AS Triangle

 

t.point(1).x = 0 : t.point(1).y = 0

t.point(2).x = 2 : t.point(2).y = 0

t.point(3).x = 1 : t.point(3).y = 1

 

Note: There is one exception, when array does not have to be dimensioned. See Data handling functions if needed.

 

Static elements

 

Element can be optionally marked as static. This means, that this field is shared between all the variables of given type.

 

TYPE Point2D

  x AS SINGLE

  y AS SINGLE

  

  STATIC description AS STRING

END TYPE

 

DIM a AS Point2D

a.x = 1 : a.y = 2

a.description = "simple 2D point"

msgBox strformat$("[{1}, {2}] is {3}", a.x, a.y, a.description)

 

DIM b AS Point2D

b.x = 3 : b.y = 4

 

msgBox strformat$("[{1}, {2}] is {3}", b.x, b.y, b.description)

 

Once you run this example, you can see that values of x and y are unique to variables a and b, however, the description of a has been promoted to b due to shared, static nature of the element. This connection works even in the other direction - if you change the static element in b now, it will be immediately reflected in a.

 

Static elements are the only type of element to have the option of initialization.

 

TYPE Point2D

  x AS SINGLE

  y AS SINGLE

  

  STATIC description AS STRING = "Simple 2D Point"

END TYPE

 

DIM p AS Point2D

 

msgBox p.description

The example will show "Simple 2D Point" message, because the p variable has the member description initialized in type / end type block.

Created with Help+Manual 8 and styled with Premium Pack Version 4 © by EC Software