I'm trying to implement a few command line arguments in my program, but I get some real strange errors...
Here's the code:
Code:
Public Function GetCommandLine(Optional MaxArgs As Integer)
On Error GoTo Error
Dim chCurrentChar, i
Dim szCmdLine, szOmitted As String
Dim nCmdLnLen, nArgs As Integer
Dim blnInArg As Boolean
 nArgs = Int(0)
 blnInArg = False

If IsMissing(MaxArgs) Then
    MaxArgs = Int(10)
End If

'Make array the correct size
ReDim ArgArray(MaxArgs)

szCmdLine = Command()
MsgBox szCmdLine
nCmdLnLen = Len(szCmdLine)

'Go through command line one character at a time and check for spaces or _
 tabs, if no space or tab then add it to the current arg string
For i = 1 To nCmdLnLen
    chCurrentChar = Mid(szCmdLine, i, 1)

    If (chCurrentChar <> " " And chCurrentChar <> Chr$(9)) Then
        'Neither space nor tab
        'Test if already in argument
        If Not blnInArg Then
            'New argument begins.
            'Test for too many arguments
            If nArgs >= MaxArgs Then
                szOmitted = Right(szCmdLine, Int(nCmdLnLen - i))
                MsgBox "Warning: Too many parameters specified, possible data loss has occurred..." + Chr$(13) + "Omitted: {" + szOmitted + "}", vbCritical, "An error has occurred"
                Exit For
            End If
            
            nArgs = nArgs + Int(1)
            blnInArg = True
        End If
        'Concatenate character to current argument
        ArgArray(nArgs) = ArgArray(nArgs) + chCurrentChar
    Else
        'Found a space or tab, so set blnInArg flag to False
        blnInArg = False
    End If
Next i

'Resize array so the UBound is the last parameter
ReDim Preserve ArgArray(nArgs)

GetCommandLine = ArgArray()
End Function
It seems to think that if MaxArgs is not specified it's 0, so it breaks immediately and gives the too many params warning. Please help me, this has really got me stumped.