Declaring variables in VBA

前端 未结 3 985
囚心锁ツ
囚心锁ツ 2020-12-11 11:45
Dim x, y as Date

What is the difference between these two code statements

Dim x as Date, y as Date

What is the pr

3条回答
  •  萌比男神i
    2020-12-11 12:31

    Dim x, y as Date
    

    is the equivalent of:

    Dim x 
    Dim y as Date
    

    and that is the equivalent of:

    Dim x as Variant
    Dim y as Date
    

    When you omit the type for a variable, it assumes the Variant type

    Edit, per your question:

    Dim a! ' same as Dim a as Short
    Dim b@ ' same as Dim b as Currency
    Dim c# ' same as Dim c as Double
    Dim d$ ' same as Dim d as String
    Dim e% ' same as Dim e as Integer
    Dim f& ' same as Dim f as Long
    

    ref: http://bytes.com/topic/visual-basic/answers/643371-declaration-shortcuts

提交回复
热议问题