DefType Statements

Purpose

set the default data type for variables and arguments.

Syntax

DefType letterrange$[, letterrange$] . . .

letterrange$: "letter1[-letter2]"

Description

The DefType commands simplify variable declaration. The letter1 and letter2 arguments specify the name range for which you can set a default data type. Each argument represents the first letter of the variable, argument, Function procedure, or Property Get procedure name and can be any letter of the alphabet. The case of letters in letterrange$ isn't significant.

letterrange$ Variables that start with
"b" 'b' (or 'B')
"bo" 'b' or 'o'
"x-z" 'x', 'y' or 'z'
"b-d,x-z" 'b' to 'd' and 'x' to 'z'.

The statement name determines the data type:

Statement Data Type
DefBool, DefBit Boolean
DefByte Byte
DefCrd Card
DefInt16, DefWrd 16-bit Integer
DefInt, DefInt32 32-bit Integer
DefLng Long
DefLar, DefInt64 Large integer (64-bit) (synonym:)
DefCur Currency
DefSng, DefFlt Single
DefDbl Double
DefDate Date
DefStr String
DefVar Variant

Example

DefCrd "bo"

Dim b = 2

Print TypeName(b) // Card

Remarks

Once the range A-Z has been specified, you can't further redefine any sub ranges of variables using Deftype statements. Once a range has been specified, if you include a previously defined letter in another Deftype statement, an error occurs. However, you can explicitly specify the data type of any variable, defined or not, using a Dim statement with an As type clause. For example, you can use the following code at module level to define a variable as a Double even though the default data type is Integer:

DefInt "A-Z"

Dim TaxRate As Double

Deftype statements don't affect elements of user-defined types because the elements must be explicitly declared. Variable types can also be declared by appending the relevant postfix characters !, |, &, %, # or $.

{Created by Sjouke Hamstra; Last updated: 28/09/2014 by James Gaite}