增加数组大小时下标超出范围
subscript out of range when increasing array size
我正在创建一个用户窗体,它在一个数组中获取尽可能多的输入。每次输入新值时,数组都会变大
当到达第二个输入时,我得到下标超出范围
Sub getFlow()
Do
thisFlow = UserForm4.TextBox1.Value
If Val(thisFlow) >= 0 Then
If isInitiated = True Then
ReDim Preserve flows(1 To UBound(flows) + 1)
Else
ReDim flows(1)
isInitiated = True
check = True
End If
flows(UBound(flows)) = thisFlow
UserForm4.TextBox1 = ""
With UserForm4.TextBox1
.SetFocus
.SelStart = 0
.SelLength = Len(.Text)
End With
Else
MsgBox "Value should be equal or greater than zero!"
End If
Exit Do
Loop
您无法在 ReDim
时指定下限 - 您只需要指定新的上限。
ReDim Preserve flows(UBound(flows) + 1)
我正在创建一个用户窗体,它在一个数组中获取尽可能多的输入。每次输入新值时,数组都会变大 当到达第二个输入时,我得到下标超出范围
Sub getFlow()
Do
thisFlow = UserForm4.TextBox1.Value
If Val(thisFlow) >= 0 Then
If isInitiated = True Then
ReDim Preserve flows(1 To UBound(flows) + 1)
Else
ReDim flows(1)
isInitiated = True
check = True
End If
flows(UBound(flows)) = thisFlow
UserForm4.TextBox1 = ""
With UserForm4.TextBox1
.SetFocus
.SelStart = 0
.SelLength = Len(.Text)
End With
Else
MsgBox "Value should be equal or greater than zero!"
End If
Exit Do
Loop
您无法在 ReDim
时指定下限 - 您只需要指定新的上限。
ReDim Preserve flows(UBound(flows) + 1)