在 VBA 中,声明具有多个属性的元素的公共常量集合/字典的最佳方法是什么?
Dim fruits as new dictionary
fruits.add "banana", array("yellow", "long", "curved")
fruits.add "watermelon", array("red", "big", "sferic")
fruits.add "blueberry", array("blue", "little", "sferic")
Run Code Online (Sandbox Code Playgroud)
我可以将其更改
Dim fruits as new dictionary
为Public fruits as new dictionary移动到顶部(外部过程),
但是如何为将使用它的多个子/函数填充该字典一次?
我可以将所有三个“添加”指令放在一个名为“fruits_populate()”的专用子中,并在我使用它的每个子/函数的开头调用此子,但有更好的解决方案吗?
为什么此代码会出现错误 6“溢出”?我糊涂了..
Sub test()
Dim i as byte
For i = 3 To 2 step - 1
Debug.Print i
Next
End Sub
Run Code Online (Sandbox Code Playgroud)
与整数类型相同。
a = 10
b = 1.11
c = 11.1
' (mathematically: 10*1.11=11.1)
debug.print a*b = c
Run Code Online (Sandbox Code Playgroud)
我得到的是False(不正确),而不是True(正确)。
我知道这种错误是由于二进制计数方式而发生的,因此我必须忍受它。
问题是:使其正常工作的最佳方法是什么?
将数字与小数进行比较时,以下是否是我们应该使用的最佳解决方案?可靠吗?
round(a*b,2) = round(c,2)
Run Code Online (Sandbox Code Playgroud)