VBAmacros:使用types修饰符的variables

我已经宣布一个整数variablestestInt简写符号如下

Dim testInt% 

使用之间有什么区别吗?

 somevalue = testInt * testInt 

 somevalue = testInt% * testInt% 

简而言之,在variables被引用的每一点上使用types说明符是否有优势?

一个快速的时间testing显示他们是线球 – 这直观上有道理

使用Long而不是Integer会更有效率。 看到这个MSFT链接

我会用更精确的API定时器重复这个

 Sub B() Dim testInt% Dim somevalue% Dim lcnt As Long Dim dbStart As Double dbStart = Timer() For lcnt = 1 To 100000000 somevalue = testInt * testInt Next MsgBox "Time was " & Timer() - dbStart End Sub Sub A() Dim testInt% Dim somevalue% Dim lcnt As Long Dim dbStart As Double dbStart = Timer() For lcnt = 1 To 100000000 somevalue = testInt% * testInt% Next MsgBox "Time for type-specified was " & Timer() - dbStart End Sub