整数与长期混淆 [英] Integer Vs Long Confusion
问题描述
我已经看到很多人相信以下
VBA将所有整数值转换为Long
事实上,即使是。
I have seen many believe in the following
VBA converts all integer values to type Long
In fact, even the MSDN article says
"In recent versions, however, VBA converts all integer values to type Long, even if they're declared as type Integer."
How is this possible? Consider this simple example.
Sub Sample()
Dim I As Integer
I = 123456789
End Sub
If VBA
converts all Integer
values to type Long
even if they're declared as type Integer, then the above should never give you the Overflow
error!
What am I missing here? Or should I take it that the statement is incorrect and pay serious heed to that the link says in the beginning
"This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release."
NOTE: I am adding the tags Excel-VBA/Powerpoint-VBA/Word-VBA/Access-VBA
hoping a VBA expert to have a look at this in case the expert doesn't monitor just the VBA
tag. I will remove these unnecessary tags once a solution has been sought.
An integer declared as an Integer
is still type checked as an Integer
. The msdn documentation is referencing how the variable is stored internally. On a 32 bit system, an Integer will be stored in 32 bytes, while on a 16 bit system, it would have been stored in 16. Hence the maximum size.
There is no type conversion going on as far as VBA is concerned. An int is an int and a long is a long, even though they now take up just as much space.
这篇关于整数与长期混淆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!