faqts : Computers : Programming : Languages : Visual basic

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

20 of 38 people (53%) answered Yes
Recently 8 of 10 people (80%) answered Yes

Entry

Can the default data type be changed; if so, how?

Jun 16th, 2000 17:37
Jerry Yoakum,


Yes, the default data type can be changed.
Background:
  The default data type for VB is Variant.  You can dimension a
  variable as Variant using two methods.
    1) Dim x as Variant
    2) Dim x
  NOTE:
    When you type:
      Dim a, b, c as Integer
    variables a and b are diminsioned as Variant.
The Answer:
  Use DefType Statements!
  A DefType Statement is used at the module level to set the default
  data type for variables, arguments passed to procedures, and the
  return type for Function and Property Get procedures whose names
  start with characters that you specify.
  Syntax:
    DefBool letterrange[, letterrange] . . .
    DefByte letterrange[, letterrange] . . .
    DefInt letterrange[, letterrange] . . .
    DefLng letterrange[, letterrange] . . .
    DefCur letterrange[, letterrange] . . .
    DefSng letterrange[, letterrange] . . .
    DefDbl letterrange[, letterrange] . . .
    DefDate letterrange[, letterrange] . . .
    DefStr letterrange[, letterrange] . . .
    DefObj letterrange[, letterrange] . . .
    DefVar letterrange[, letterrange] . . .
  Example:
    ' The following line of code will allow a programmer to simply type
    ' dim bTemp to diminsion bTemp as type Boolean.
    DefBool b
    Sub Main()
      Dim bTemp
      bTemp = True
      msgbox VarType(bTemp)
    End Sub
    ' A value of 11 will be displayed, which indecates that bTemp is
    ' diminsioned as type Boolean.