Can I dim multiple objects as Integer / Variant / etc. in one line?

 ̄綄美尐妖づ 提交于 2019-12-01 22:03:28

问题


In VBA, can I Dim multiple objects as Integers in a single line in this concise fashion, or does this declare only d be an Integer?

Dim a, b, c, d As Integer

回答1:


You can test:

Sub test()
    Dim a, b, c, d As Integer
    Debug.Print TypeName(a)
    Debug.Print TypeName(b)
    Debug.Print TypeName(c)
    Debug.Print TypeName(d)
End Sub

The output in the immediate window:

Empty
Empty
Empty
Integer

The empty might be slightly confusing, but it makes it clear that only the last is an integer. Using F8 to step though the code, while viewing the results in the Locals Window is even more informative since then the types of a,b,c are explicitly given as Variant/Empty.



来源:https://stackoverflow.com/questions/30985795/can-i-dim-multiple-objects-as-integer-variant-etc-in-one-line

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!