整数与长混淆 [英] Integer Vs Long Confusion

查看:26
本文介绍了整数与长混淆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到很多人相信以下内容

VBA 将所有整数值转换为 Long 类型

事实上,即使是 ,但 int 是 int 而 long 是 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

解决方案

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 BITS not Bytes, while on a 16 bit system the value is stored in a 16 BIT space or register, 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆