René Nyffenegger's collection of things on the web
René Nyffenegger on Oracle - Most wanted - Feedback -
 

Datatypes [VBA]

' type person_t
' 
'   first_name  as string
'   middle_name as string
'   last_name   as string
' 
'   birth_day   as date
' 
' end type


sub some_func

  dim bo as boolean
  dim by as byte
  dim dt as date

  dim cu as currency   ' @
  dim db as double     ' #
  dim it as integer    ' %
  dim lo as long       ' &
  dim si as single     ' !
  dim st as string     ' $

  dim va as variant

  dim ob as object


  dim ary(1 to 4, 1 to 2) as single 

  ary(1, 1) =   1: ary(1, 2) =   5 
  ary(2, 1) =   2: ary(2, 2) =   6 
  ary(3, 1) =   3: ary(3, 2) =   7 
  ary(4, 1) =   4: ary(4, 2) =   8 

' dim dc as decimal    ' decimal cannot be declared.


'   dim person as person_t
' 
'   person.first_name = "John"
'   person.last_name  = "Deere"
' ' person.birth_day  = 

  bo = true

  by = 1
  by = 0
  by = 255

  ' The following two lines cause an error, since
  ' range of byte is 0 .. 255
  ' by = -1
  ' by = 256

  dt = #12/13/2007#    ' Format of date: mm/dd/yyyy ???

  db = 1.245

  it = 4

  it = 4.2

  msgbox("it: " & it) ' 4, not 4.2 (it is an integer)

' Variants can be assigned some special values:
  va = empty
  va = null
  va = error
' va = nothing

' It seems possible to assign empty to variables
' of other data types as well.
  it = empty


  for each el in ary
    ' Message Box will "output" 1 .. 8
      msgbox(el)
  next el

end sub