|
Type | |||||||
Type <.typeName.> [As <.typeName.>] ... EndType | |||||||
Parameters: NONE | |||||||
Returns: NONE | |||||||
You can define your own data types with Type declarations. User defined types in PlayBASIC are very similar to Structs in C/C++ or Records in Pascal and contain one or more Fields. A simple type definition might look like this:
This declaration block defines a type called MyType that contains six fields. An integer field called Field1, a float field called Field2#, a string field called Field3$, a static Integer array field called ArrayField4(), a static float array field called ArrayField5#(), and static String array field called ArrayField6$() Note: In the example above we've used the short cut declarations. What's that ? - Well, to indicate the data type of each field we're using the postfix symbols. So a string field uses the $ symbol in the field name, and Floats use their # postfix. This is a handy short cut for basic datatypes such as Integers,Floats and String. But you can also use long hand declarations (Which is in some situations is required!), which use the "as datatype" convention. For example,
In this example we're added long hand declaratiosn to some of the fields. These allow us to specificly define what each field should be. In order to use this type you need to delcare a variable with this type:
You can also declare an array where each cell stores it's own set of MyType fields
To access each defined type field of the new variable you type the variable name followed by a dot (.) and then the field name:
Each field of a type can either be of a basic type (Integer, Float or String) or a previously user defined type:
PlayBASIC offers another feature called Inherited Types. That means that you can inherit the fields of a previously defined type in a new type. Example:
With As statement the type "TAllDetails" inherits all the fields of "TNameAge". Therefore the type "TAllDetails" now has the following fields: Name$ Age Address$ FavouriteColour$ Weight# To learn more about TYPES please read the TYPES Tutorial |
Related Info: | Dim | EndType | For | LinkedLists | Pointer | TypeOf | Types : |
|
|||||||||||||||||||||||||||||||||||||||
(c) Copyright 2002 - 2024 - Kevin Picone - PlayBASIC.com |