MC-Basic:STRUCTURE TYPE DEFINITION

From SoftMC-Wiki
Jump to: navigation, search
Language: English  • 中文(简体)‎

Because a structure is a new data type, it must first be defined. Only then the name of the new data type structure can be used to declare a structure variable. Structure data type definition can be done within the declarations part of the config.prg file (before the PROGRAM block), or a library file (before the first function block). This block defines names, types and array sizes of structure elements.

The different types that are supported for the structure are the following: long, double, string, joint and location, generic axis, generic group, semaphore, user error and user note.

User error and note structure elements are generic, i.e., should be assigned to acquire error number and message.

Syntax

TYPE <structure_type_name>

<field_name>{[<index>]…} as <type> {<of> <type>}

END TYPE

Availability

from 0.4.0.20  version

Scope

Configuration only. Definition in library context is also available since version 4.5.18.

Limitations

  • Array structure elements cannot have more than 10 dimensions.
  • Semaphore structure elements can only be scalars.
  • User errors and notes structure elements can only be scalars.
  • Changes in type definition are not allowed during reloading of the library.

Examples

Type ST
  LngElem           as long                        'Long scalar element
  LngArr[10]        as long                        'Long array element
  DblElem           as double                      'Double scalar element
  DblArr[2][3]      as double                      'Double array element
  StrElem           as string                      'String scalar element
  StrArr[4][2][5]   as string                      'String array element
  JntElem           as joint of XYZ                'Joint scalar element
  JntArr[7][10][3]  as joint of XYZ                'Joint array element
  LocElem           as location of XYZR            'Location scalar element
  LocArr [6]        as location of XYZR            'Location array element
  Ax1               as generic axis                'Generic axis scalar element
  Axarr1[4]         as generic axis                'Generic axis array element
  Gr1               as generic group               'Generic group scalar element
  Grarr1[3][5]      as generic group               'Generic group array element
  Sem1              as semaphore                   'Semaphore element
  Err1              as error                       'User error element
  Nt1               as note                        'User note element
End Type

'usage
dim st1 as ST
st1->DblElem = 0.1

See Also