【问题标题】:Why does this code in VBA Power Point work fine witout Dim commands for numbers?为什么 VBA Powerpoint 中的这段代码在没有数字的 Dim 命令的情况下可以正常工作?
【发布时间】:2010-12-15 16:18:10
【问题描述】:

从一个 VBA 教程中我了解到,连续数字的变量应该首先声明为整数:

Dim mynumber as integer

但是,请看这段代码:

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

这里没有将变量声明为整数,但它仍然可以正常工作。为什么会这样?

【问题讨论】:

    标签: vba variables integer numbers dimension


    【解决方案1】:

    默认情况下,VB 不需要变量声明。这引起了很多挫败感,因为这意味着在运行时出现问题之前不会检测到拼写错误。

    要更改此设置,请将Option Explicit 添加到文件顶部。

    【讨论】:

      猜你喜欢
      • 2015-09-06
      • 2015-09-17
      • 1970-01-01
      • 2019-02-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-23
      • 2020-03-07
      相关资源
      最近更新 更多