vb6:2D动态数组的重新定义 [英] vb6: redimensioning of 2D dynamic array

查看:184
本文介绍了vb6:2D动态数组的重新定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用数组根据蒸汽的压力存储蒸汽的特性。现在,我具有9个压力的属性,因此我使用的是静态数组。我想更灵活一些,所以我想切换到动态数组。

I am using arrays to store properties of steam according to it's pressure. Right now I have properties of exactly 9 pressures so I'm using static array. I'd like to be more flexible so I'd like to switch to dynamic arrays.

当我使用 ReDim foo(1,i, 1至10)循环中,我完全松开除最后一行以外的所有数据。

当我使用 ReDim Preserve foo(1至i,1至10) ReDim Preserve(i,10)程序抛出错误运行时错误'9':下标超出范围 i 从1到9。

When I use ReDim foo(1 to i, 1 to 10) in loop I completely loose all data except last line.
When I use ReDim Preserve foo(1 to i, 1 to 10) or ReDim Preserve(i,10) Program throws error of "Runtime error '9': subscript out of range". i goes from 1 to 9.

如何在不丢失数据的情况下添加行/列来填充全部数据?

How can I add line/column to array full of data without loosing them?

推荐答案

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

You may only Redim Preserve the final dimension in a VB6 multidimensional array. Here's the info from MSDN:


如果包含Preserve关键字,则
Visual Basic将复制
中的元素现有阵列到新阵列。
使用Preserve时,仅可以调整数组的最后一个维度
的大小,即
,对于其他每个维度,您必须
指定与已经具有的大小相同的大小
例如,如果您的数组只有一个维度
,则可以调整该
维度的大小,并仍然保留该$ b的空间。

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.

$ b数组的内容,因为它是
的最后一个也是唯一的维。但是,如果数组具有两个或多个
维,则
,如果使用
Preserve,则只能更改最后一个维的
大小。

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)

这篇关于vb6:2D动态数组的重新定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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