ReDim保存错误 [英] ReDim Preserve error

查看:43
本文介绍了ReDim保存错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试重新保存二维数组.在我的代码的最顶部,我有:

I am trying to redim preserve a two dimensional array. at the very top of my code I have:

Dim BayQuestionArray() As Variant
Dim numberofbay As Double

我有两个按钮,第一个按钮用于初始化数组大小:

I have two buttons, the first button is for initializing the array size:

numberofbay = 1
ReDim Preserve BayQuestionArray(numberofbay, 37)

第二个按钮用于放大数组

and the second button is for upsizing the array

ReDim Preserve BayQuestionArray(numberofbay + 1, 37)

第二个按钮不起作用,它一直给我一个错误,提示运行时错误9下标超出范围".为什么?

The second button doesn't work, it keeps giving me an error saying Run time error 9 Subscript out of range. Why?

推荐答案

使用Preserve调整数组变量的大小(这样声明,而不是Variant)时,您只能更改上边界 最后一个维度.您需要转置数组,或使用锯齿状数组或其他结构(如Dictionary/Collection).

When using Preserve to resize an array variable (declared as such, not as Variant), you may only alter the upper boundary of the last dimension. You would need to transpose your array, or use a jagged array or other structure like a Dictionary/Collection.

这篇关于ReDim保存错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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