English 中文(简体)
公共动力 2. 轨道回归率
原标题:Public Dynamic Array returns error
  • 时间:2009-08-21 10:40:06
  •  标签:

在座各位都错了。

Run-time error  9 :
Subscript out of range 

缩略语

Public newarray() As String

Sub test1() 
    Dim int1 As Integer 
    int1 = 0
    Do 
        int1 = int1 + 1 
        newarray(int1) = int1 * 5     
    Loop Until int1 > 3
End Sub

i) 救助阵列

Public newarray(4) As string

但我要宣布一个充满活力的阵列。 请提供帮助。 谢谢。

最佳回答

可通过<代码>ReDim来分配阵列面积:

Public newarray() As String

Sub test1() 

    Dim int1 As Integer 
    ReDim newarray(4)

    int1 = 0

    Do 

        int1 = int1 + 1 

        newarray(int1) = int1 * 5 

    Loop Until int1 > 3

End Sub

这将重新界定你们的整个阵列。 如果你需要保留阵列的内容,并且只是改变规模,你可以使用<代码>。 ReDim P reserves newarray(4)。

你的法典认为,阵列有1个。 这可以基于0(根据VB的选择)。 为保证您的守则,不论这一选择如何,您应使用<代码>LBound/ UBound,以限制您的反响:

    int1 = LBound(newarray)

    Do 

        newarray(int1) = int1 * 5 

        int1 = int1 + 1 


    Loop Until int1 > UBound(newarray)
问题回答

暂无回答




相关问题
热门标签