arrays - vb6:二维动态数组的重新标注

标签 arrays multidimensional-array vb6 dynamic-arrays

我使用数组根据压力存储 Steam 的属性。现在我有正好 9 个压力的属性,所以我使用静态数组。我想要更灵活,所以我想切换到动态数组。

当我在循环中使用 ReDim foo(1 to i, 1 to 10) 时,我完全丢失了除最后一行之外的所有数据。
当我使用 ReDim Preserve foo(1 to i, 1 to 10)ReDim Preserve(i,10) 程序抛出错误 “Runtime error '9' : 下标超出范围”i 从 1 到 9。

如何在不丢失数据的情况下将行/列添加到充满数据的数组中?

最佳答案

您只能在 VB6 多维数组中保留 final 维度。这是来自 MSDN 的信息:

If you include the Preserve keyword, Visual Basic copies the elements from the existing array to the new array. When you use Preserve, you can resize only the last dimension of the array, and for every other dimension you must specify the same size it already has in the existing array.

For example, if your array has only one dimension, you can resize that dimension and still preserve the contents of the array, because it is the last and only dimension. However, if your array has two or more dimensions, you can change the size of only the last dimension if you use Preserve.

The following example increases the size of the last dimension of a dynamic array without losing any existing data in the array, and then decreases the size with partial data loss:

 Dim IntArray(10, 10, 10) As Integer 
 ReDim Preserve IntArray(10, 10, 20) 
 ReDim Preserve IntArray(10, 10, 15)

关于arrays - vb6:二维动态数组的重新标注,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6276761/

相关文章:

javascript - 如何获取数组中最大的数字和对应的名称?

javascript - 使用某种方法编写一个函数来检查数组中的项目是否等于 null (JavaScript)

java - 读取文本字段数组

c# - 将 List<double[]> 转换为 double[,]

vb6 - 有人记得 VB3 中的语句/命令 "WaitOn"是什么意思吗?

vb6 - 如何在 Visual Basic 6 中为每个列表项命名

javascript - Protractor - 循环遍历不同的定位器以填充数组

php - 如何从 php 向 Titanium mobile 发送和接收多维数组?

c - 用零初始化一个二维数组;打印其值表明并非每个元素都包含 0

vb6 - 编译VB 6程序时如何修复 "Unexpected error (32801)"?