VB6和VB7的Longptr数据类型 [英] Longptr datatype for VB6 and VB7

查看:82
本文介绍了VB6和VB7的Longptr数据类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我面临的问题是,我想分发我的Excel VBA模板之一.在几乎所有过程中,我都分配了LONG数据类型.但是,我发现对于VBA7或2010及更高版本,我们可以使用LongPtr数据类型进行分配.这将绕过版本控制问题.无论是64位还是32位的MS Office.

What issue I'm facing is, I want to distribute one of my Excel VBA Template. Almost in all procedure, I have assigned LONG datatype. but, I found that for VBA7 or 2010 and later version, we can use LongPtr datatype for assigning. which will bypass the versioning issue. whether it will be a 64bit or 32bit of MS office.

但是我的一位同伴指出,我不能将LongPtr用于VB6或2010年下半年的办公室.

But one my mate has pointed out I can't use LongPtr for VB6 or for lower of 2010 office.

因此,我尝试以某种方式使用它,使其更适用于任何Office版本

So I have tried to use in the way to make it more usable for any office version

#If VBA7 Then
    Dim X As LongPtr
#Else
    Dim X As Long
#End If

我应该使用上面的声明吗?会导致错误吗?据我的朋友说,这会造成的.他还补充说,编译器将绕过if语句.

Should I use above declaration? Will it cause the error? According to my friend, It will cause. He also added that compiler will bypass the if statement.

我没有系统可以对其进行测试.

I don't have a system to test it.

我当前的系统是

Windows 10 64位

Windows 10 64bit

MS Office 2016 32位

MS Office 2016 32bit

请建议我,我在哪里想念这个概念.为什么我不能在过程中使用以上声明?

Please suggest me, where I'm missing the concept. And Why I can't use the above declaration in procedure?

谢谢.

推荐答案

#If VBA7 Then
    Dim X As LongPtr
#Else
    Dim X As Long
#End If

我应该使用上面的声明吗?会导致错误吗?

Should I use above declaration? Will it cause the error?

是的,您应该使用上面的声明,即使在较旧的Office版本中,它也不会导致错误.

Yes, you should use the above declaration, and it will not cause an error, even in an ancient version of Office.

但是,您应该了解何时以及为什么需要使用 LongPtr 而不是 Long 开始.
Long 在所有版本中都存在,并且在所有版本中(32位整数)表示相同的意思.为此,您不应将其更改为 LongPtr .您仅应将 LongPtr 用于指针或指针大小的数据类型.

However, you should understand when and why you need to use LongPtr instead of Long to begin with.
Long exists in all versions and means the same thing in all versions (32-bit integer). You should not change it to LongPtr for the sake of it. You should only use LongPtr for pointers or pointer-sized data types.

这篇关于VB6和VB7的Longptr数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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