User-Defined Data Types

From Wikibooks, open books for an open world
Jump to navigation Jump to search


Enumerated Data Types[edit]

Declaring Enumerated Data Types[edit]

Language General Usage Example Usage
Pseudocode
TYPE <Identifier> = (<Value 1>, <Value 2>, <Value 3>, ...)
TYPE Season = (Summer, Autumn, Winter, Spring)
TYPE Direction = (North, North_East, East, South_East, South, South_West, West, North_West)
TYPE SpiceIntensity = (No_Preference ,None, Mild, Medium, Hot, Extreme)
VB.NET
Enum <Identifier>
 <Value 1> = <Reference>
 <Value 2> = <Reference>
 <Value 3> = <Reference>
 ....
End Enum
Enum Season
 Summer = 1
 Autumn = 2
 Winter = 3
 Spring = 4
End Enum

Enum SpiceIntensity
 None = 0
 Mild = 1
 Medium = 2
 Hot = 3
 Extreme = 4
End Enum

Using Enumerated Data Types[edit]

Language General Usage Example Usage
Pseudocode
DECLARE <Identifier> : <Data Type>
<Identifier> ← <Value>
DECLARE Seasons : Season
Seasons ← Autumn

DECLARE CompassPointer : Direction
CompassPointer ← North

DECLARE SpicePreference : SpiceIntensity
SpicePreference ← Extreme
VB.NET
Dim <Identifier> As <Data Type>
<Integer Variable> = <Identifier>.<Value>
Dim Seasons As Season
SeasonCounter = Seasons.Autumn

Dim CompassPointer As Direction
CurrentDirection = CompassPointer.North

Dim SpicePreference As SpiceIntensity
SpiceCounter = SpicePreference.Extreme

Pointer Data Types[edit]

There is no VB.Net equivalent for a Pointer Data Type.

Language General Usage Example Usage
Pseudocode
TYPE <Pointer> = ^<Type Name>
Type AddPointer = ^INTEGER
Type NextLocation = ^STRING
Type Pass = ^REAL

Record Data Types[edit]

Language General Usage Example Usage
Pseudocode
TYPE <Identifier>
 DECLARE <Identifier> : <Data Type>
 DECLARE <Identifier> : <Data Type>
 ...
END TYPE
TYPE Person
 DECLARE Name : STRING
 DECLARE Birthday : DATE
 DECLARE Weight : REAL
 DECLARE Address : STRING
 DECLARE SpicePreference : SpiceIntensity
END TYPE
VB.NET
Structure <Identifier>
 Dim <Identifier> As <Datatype>
 Dim <Identifier> As <Datatype>
 ...
End Structure
Structure Person
 Dim Name As String
 Dim Birthday As Date
 Dim Weight As Double
 Dim Address As String
 Dim SpicePreference As SpiceIntensity
End Structure