gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 23:19:13 25 4
gpt4 key购买 nike

我使用数组根据压力存储 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com