DefType (statement)

Syntax DefInt letterrange DefLng letterrange DefStr letterrange DefSng letterrange DefDbl letterrange DefCur letterrange DefObj letterrange DefVar letterrange DefBool letterrange DefDate letterrange
Description Establishes the default type assigned to undeclared or untyped variables.
Comments The Def Type statement controls automatic type declaration of variables. Normally, if a variable is encountered that hasn't yet been declared with the Dim , Public , or Private statement or does not appear with an explicit type-declaration character, then that variable is declared implicitly as a variant ( DefVar A–Z) . This can be changed using the Def Type statement to specify starting letter ranges for type other than integer. The letterrange parameter is used to specify starting letters. Thus, any variable that begins with a specified character will be declared using the specified Type.
The syntax for letterrange is:  letter [-letter] [,letter [-letter]]... Def Type variable types are superseded by an explicit type declaration¾using either a type-declaration character or the Dim , Public , or Private statement.
The Def Type statement only affects how the Basic Control Engine compiles scripts and has no effect at runtime. The Def Type statement can only appear outside all Sub and Function declarations. The following table describes the data types referenced by the different variations of the Def Type statement:
Statement Data Type
DefInt Integer
DefLng Long
DefStr String
DefSng Single
DefDbl Double
DefCur Currency
DefObj Object
DefVar Variant
DefBool Boolean
DefDate Date
Example
DefStr a-m
DefLng n-r
DefSng s-u
DefDbl v-w
DefInt x-z
Const crlf = Chr$(13) + Chr$(10)
Sub Main()
  a = 100.52
  n = 100.52
  s = 100.52
  v = 100.52
  x = 100.52
  msg1 = "The values are:" & crlf & crlf
  msg1 = msg1 & "(String) a: " & a & crlf
  msg1 = msg1 & "(Long) n: " & n & crlf
  msg1 = msg1 & "(Single) s: " & s & crlf
  msg1 = msg1 & "(Double) v: " & v & crlf
  msg1 = msg1 & "(Integer) x: " & x & crlf
  MsgBox msg1
End Sub
See Also Currency (data type); Date (data type); Double (data type); Long (data type); Object (data type); Single (data type); String (data type); Variant (data type); Boolean (data type); Integer (data type).