Deftype Statements Example

This example shows various uses of the Deftype statements to set default data types of variables and function procedures whose names start with specified characters. The default data type can be overridden only by explicit assignment using the Dim statement. Deftype statements can only be used at the module level (that is, not within procedures).

' Variable names beginning with A through K default to Integer.
DefInt A-K
' Variable names beginning with L through Z default to String.
DefStr L-Z
CalcVar = 4    ' Initialize Integer.
StringVar = "Hello there"    ' Initialize String.
AnyVar = "Hello"     ' Causes "Type mismatch" error.
Dim Calc As Double    ' Explicitly set the type to Double.
Calc = 2.3455    ' Assign a Double.

' Deftype statements also apply to function procedures.
CalcNum = ATestFunction(4)    ' Call user-defined function.
' ATestFunction function procedure definition.
Function ATestFunction(INumber)
    ATestFunction = INumber * 2    ' Return value is an integer.
End Function