Home      Downloads             Documentation      FAQ     

Documentation>ETP-Basic reference>User-defined types

 

User-defined types

You saw that you can declare variables of different types, like Integer, Long, String, etc...

User-defined types allows you to group variables together. You will sometimes have to group several variables in one to define something very special. Each variable in this group (called "field") will represents a property of this entity.

Declaration of a new type:

To declare a new type, here is the syntax :

Type TypeName
'fields...
EndType

In the 'fields..., you must put the fields of the type.

For example, if you create a type to describe somebody, you can take severals things like name, age, phone number. The declaration will look like this :

Type Person
Name as String
Age as Integer
Phone as Long
EndType

Variable declaration :

Local VariableName as TypeName

or

Public VariableName as TypeName

To declare a variable of a type you defined, it is the same syntax. For our example of Person type, we would declare variables like this :

Local Marc as Person

So, you can use the fields of the variable Marc :

Marc.Name = "Marc Smith"
Marc.Age = 34
Marc.Phone = 98324348532
'...
'birthday !
Marc.Age = Marc.Age + 1

A bit futher, use of arguments :

You can also use user-defined types for arguments of functions and procedures. The syntax is the same as for classic variables. Following example shows the use of a type defined by the programmer during a function call :

Procedure DisplayName : (a as Person)
Locate 2,2, a.Name , 4
'...instructions

 

Documentation>ETP-Basic reference>User-defined types

     
    About ETP Contact Us