开发者

Why does this code in VBA Power Point work fine witout Dim commands for numbers?

From one of VBA tutorials I learned that variables contining numbers should be firstly declared as integers:

Dim mynumber as integer

But, please, look at this code:

Sub math()
   A = 23
   B = 2
   ABSumTotal = A + B
   strMsg = "The answer is " & "$" & ABSumTotal & "."
   MsgBox strMsg
   strMsg = "The answer is " & "$" & Sqr(ABSumTotal) & "."
   MsgBox strMsg 
End Sub

No variables are declared here as integer, but it still works just fine.开发者_开发技巧 Why is it so?


By default, VB does not require variable declarations. This has caused lots of frustration because it means that typos go undetected until something breaks at runtime.

To change this, add Option Explicit to the top of the file.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜