Def... Statement |
DefBool letterrange[,letterrange] DefByte letterrange [,letterrange] DefInt letterrange [,letterrange] DefLng letterrange [,letterrange] DefCur letterrange [,letterrange] DefSng letterrange [,letterrange] DefDbl letterrange [,letterrange] DefDec letterrange [,letterrange] DefDate letterrange [,letterrange] DefStr letterrange [,letterrange] DefObj letterrange [,letterrange] DefVar letterrange [,letterrange]
|
Used at module level to define a default data type for variables, arguments passed to procedures, and the return type for Function and Property Get procedures whose names start with the specified characters. For example, the statement DefStr s tells your program that every variable, function, and argument beginning with the letter "s" is a string data type.
The statement name determines the data type:
Statement | Data Type |
---|---|
DefBool | Boolean |
DefByte | Byte |
DefInt | Integer |
DefLng | Long |
DefCur | Currency |
DefSng | Single |
DefDbl | Double |
DefDec | Decimal |
DefDate | Date |
DefStr | String |
DefObj | Object |
DefVar | Variant |
You can override the default data types defined with Def... by using the Dim statement.
Def... statements have scope only within the module in which they appear. There is no such thing as a public or global Def... statement for the project.
DefStr s DefDbl d DefInt i ... iMyInteger = 100 dMyDouble = 122345.899 sMyString = "Hello World"
Elements of user-defined types aren't affected by Def... statements because the elements must be explicitly declared.
Def... statements must appear before all other declarations within the declarations section of a module.
If your code includes the Option Explicit statement, which indicates that your application relies on strong variable typing, Def... statements for the most part are rendered superfluous, since the Dim statement is still required to declare each variable. However, in this case, the Def... statement defines the data type of variables whose Dim statements don't specify a specific data type. For example, in the code fragment:
Option Explicit DefStr s Public strMyVar1
strMyVar1 has been defined as a string by the DefStr statement.