Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays 如果与下标的比较超出范围_Arrays_Vba_If Statement - Fatal编程技术网

Arrays 如果与下标的比较超出范围

Arrays 如果与下标的比较超出范围,arrays,vba,if-statement,Arrays,Vba,If Statement,我不明白当 strArray0的下标超出范围。我的布尔变量变为true,我不希望这样 If Left(strArray(0), 3) = "Usu" Then booleanVariable = True End If 在尝试执行字符串操作之前,请确保数组0不为空 sub t If Initialized(strArray) Then ' is array setup If strArray(0) <> "" Then ' if array has val

我不明白当 strArray0的下标超出范围。我的布尔变量变为true,我不希望这样

If Left(strArray(0), 3) = "Usu" Then
     booleanVariable = True    
End If

在尝试执行字符串操作之前,请确保数组0不为空

sub t
If Initialized(strArray) Then ' is array setup
    If strArray(0) <> "" Then ' if array has value
        If Left(strArray(0), 3) = "Usu" Then
             booleanVariable = True
        End If
    Else
        MsgBox "No value in array"
    End If
Else
    MsgBox "Array not setup"
End If
end sub

Function Initialized(val) As Boolean
On Error GoTo errHandler
    Dim i

    If Not IsArray(val) Then GoTo exitRoutine

    i = UBound(val)

    Initialized = True
exitRoutine:
    Exit Function
errHandler:
    Select Case Err.Number
        Case 9 'Subscript out of range
            GoTo exitRoutine
        Case Else
            Debug.Print Err.Number & ": " & Err.Description, _
                "Error in Initialized()"
    End Select
    Debug.Assert False
    Resume
End Function

我不明白标题是怎么指这个问题的。。。0是否超出strArray的范围?如果是这样的话,您可能有一个On Error Resume Next,它可能会导致代码通过If语句执行If语句,甚至使用On Error Resume Next。如果您知道strArray0超出范围,为什么要在代码中写入它?如果只是查找数组的第一个元素,则可以使用StrarrayBoundStrarrayIt,因为strArray0=立即尝试上面的内容,所以StrarrayIt不起作用。你能做什么?直接窗口中的strArray0?