I am used to use the following code on Excel 2010 (Windows 7 64-bit), and It works good.
我习惯在Excel 2010(Windows 7 64位)上使用以下代码,并且它运行良好。
Sub code_on_2010()
Dim i As Long
i = InputBox("input integer number")
ReDim a(i) As Variant
'....
End Sub
Recently, I upgrade my PC to Windows 10(64-bit) and Excel 2016(64-bit). As I know the new type name for 64-bit Long integer type, I rewrite my code as below:
最近,我将我的PC升级到Windows 10(64位)和Excel 2016(64位)。我知道64位长整数类型的新类型名称,我重写我的代码如下:
Sub code_on_2016_with_LongPtr()
Dim i As LongPtr
i = InputBox("input integer number")
ReDim a(i) As Variant
'...
End Sub
It returns a Type mismatch (Error 13)
Error.
它返回类型不匹配(错误13)错误。
Even I replace the LongPtr with LongLong (as below), it returns Type mismatch
error, too.
即使我用LongLong替换LongPtr(如下所示),它也会返回类型不匹配错误。
Sub code_on_2016_with_LongLong()
Dim i As LongLong
i = InputBox("input integer number")
ReDim a(i) As Variant
'...
End Sub
Could anybody tell me why I cannot ReDim an array with index of LongPtr or LongLong type in Excel 2016 VBA?
有人可以告诉我为什么我不能在Excel 2016 VBA中使用LongPtr或LongLong类型的索引重新编译数组?
1 个解决方案
#1
0
Excel 64 bits won't need LongPtr or LongLong in your code:
Excel 64位代码中不需要LongPtr或LongLong:
Option Explicit
Sub code_on_2010()
Dim i As Long 'declaring any other type won't speed up your code, and won't give a bigger range of possible numbers!
Dim h$
Dim a() 'basically says : a is a variable sized array of type variant
h = InputBox("input integer number") 'returns a string
if isnumeric(h) then i=clng(h)
ReDim a(i)
'....
End Sub
#1
0
Excel 64 bits won't need LongPtr or LongLong in your code:
Excel 64位代码中不需要LongPtr或LongLong:
Option Explicit
Sub code_on_2010()
Dim i As Long 'declaring any other type won't speed up your code, and won't give a bigger range of possible numbers!
Dim h$
Dim a() 'basically says : a is a variable sized array of type variant
h = InputBox("input integer number") 'returns a string
if isnumeric(h) then i=clng(h)
ReDim a(i)
'....
End Sub