Table of contents
TOC
Collapse the table of content
Expand the table of content

Deftype Statements

office 365 dev account|Last Updated: 6/12/2017
|
1 Contributor

Used at module level to set the defaultdata type forvariables, arguments passed toprocedures, and the return type for Function and PropertyGet procedures whose names start with the specified characters. SyntaxDefBoolletterrange [ ,letterrange ] . . .DefByteletterrange [ ,letterrange ] . . .DefIntletterrange [ ,letterrange ] . . .DefLngletterrange [ ,letterrange ] . . .DefLngLngletterrange [ ,letterrange ] . . . (Valid on 64-bit platforms only.) DefLngPtrletterrange [ ,letterrange ] . . .DefCurletterrange [ ,letterrange ] . . .DefSngletterrange [ ,letterrange ] . . .DefDblletterrange [ ,letterrange ] . . .DefDecletterrange [ ,letterrange ] . . .DefDateletterrange [ ,letterrange ] . . .DefStrletterrange [ ,letterrange ] . . .DefObjletterrange [ ,letterrange ] . . .DefVarletterrange [ ,letterrange ] . . . The required letterrange argument has the following syntax: letter1 [ -letter2 ] 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. Remarks The statement name determines the data type:

StatementData Type
DefBoolBoolean
DefByteByte
DefIntInteger
DefLngLong
DefLngLngLongLong (Valid on 64-bit platforms only.)
DefLngPtrLongPtr
DefCurCurrency
DefSngSingle
DefDblDouble
DefDecDecimal (not currently supported)
DefDateDate
DefStrString
DefObjObject
DefVarVariant

For example, in the following program fragment, is a string variable: A Deftype statement affects only themodule where it is used. For example, a DefInt statement in one module affects only the default data type of variables, arguments passed to procedures, and the return type for Function and PropertyGet procedures declared in that module; the default data type of variables, arguments, and return types in other modules is unaffected. If not explicitly declared with a Deftype statement, the default data type for all variables, all arguments, all Function procedures, and all PropertyGet procedures is Variant. When you specify a letter range, it usually defines the data type for variables that begin with letters in the first 128 characters of the character set. However, when you specify the letter range A-Z, you set the default to the specified data type for all variables, including variables that begin with international characters from the extended part of the character set (128-255). Once the range A-Z has been specified, you can't further redefine any subranges 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 Astype 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: Deftype statements don't affect elements ofuser-defined types because the elements must be explicitly declared.

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).

© 2017 Microsoft