【问题标题】:In VBA : Dim a, b as String ==> only b is a String. Can I get a reference to this behavior?在 VBA 中:Dim a, b as String ==> 只有 b 是一个字符串。我可以参考这种行为吗?
【发布时间】:2017-01-19 02:37:50
【问题描述】:

在 Access 2013 的 VBA 模块中,我被这个咬了:

Dim a, b as String

a 是变体,b 是字符串

我在哪里可以获得有关此行为的参考?

在 MSDN 页面 "Dim Statement (Visual Basic)" 我看到以下示例:

   Dim a, b, c As Single, x, y As Double, i As Integer  
   ' a, b, and c are all Single; x and y are both Double

这不是相同的行为。

【问题讨论】:

标签: ms-access vba


【解决方案1】:

您正在查看错误的文档。 VB 不是 VBA。

来自VBA documentation:

您可以在一个语句中声明多个变量。要指定数据类型,您必须包括每个变量的数据类型。在下面的语句中,变量intX、intY和intZ被声明为Integer类型。

Dim intX As Integer, intY As Integer, intZ As Integer 

在以下语句中,intX 和 intY 仅声明为 Variant 类型,intY 声明为 Variant 类型,仅声明了 intZ作为类型整数。

Dim intX, intY, intZ As Integer 

您不必在声明语句中提供变量的数据类型。如果省略数据类型,则变量将是 Variant 类型。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-09-13
    • 1970-01-01
    • 2012-04-09
    • 1970-01-01
    • 2014-01-05
    • 1970-01-01
    • 1970-01-01
    • 2018-03-04
    相关资源
    最近更新 更多