I have an array with 3 elements.
Using the code below, if I call getargs(Args, 4), the code runs through the "if /else/end if" section error free but returns "subscript out of range" when it encounters the "IIf() statement.
Is this a peculiarity of arrays, that they don't like the iif() statement or is there something else at play here?
	
	
	
		
 Using the code below, if I call getargs(Args, 4), the code runs through the "if /else/end if" section error free but returns "subscript out of range" when it encounters the "IIf() statement.
Is this a peculiarity of arrays, that they don't like the iif() statement or is there something else at play here?
		Code:
	
	
	Private Sub Command100_Click()
    Dim Args As String
    Dim str As String
    Args = "tablelegs~Windows~letter box"
    str = getArgs(Args, 4)
End Sub
Private Function getArgs(Args As String, nNum As Integer) As String
    Dim aArgs() As String
    nNum = nNum - 1
    aArgs() = Split(Args, "~")
    If nNum > UBound(aArgs) Then
        getArgs = "xxx"
    Else: getArgs = aArgs(nNum)
    End If
MsgBox getArgs
    getArgs = IIf(nNum > UBound(aArgs), "", aArgs(nNum))
End Function 
	 
 
		