VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



How to implement command-line parameters in Visual Basic

by Syed Natiq Abbas Kazmi (3 Submissions)
Category: Miscellaneous
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Sun 27th July 2003
Date Added: Mon 8th February 2021
Rating: (1 Votes)

How to implement command-line parameters in Visual Basic

Rate How to implement command-line parameters in Visual Basic




Function GetCommandLine(Optional NumberOfArguments)
     •-- Declare variables.
     Dim C, CmdLine, CmdLnLen, InArg, I, ArgNum
     •-- See if NumberOfArguments was provided.
     If IsMissing(NumberOfArguments) Then
     NumberOfArguments = 10
     End If
     •-- Make array of the correct size.
     ReDim ArgArray(NumberOfArguments)
     ArgNum = 0
     InArg = False
     •-- Get command line arguments.
     CmdLine = Command()
     CmdLnLen = Len(CmdLine)
     •-- Go thru command line one character
     •-- at a time.
     For I = 1 To CmdLnLen
     C = Mid(CmdLine, I, 1)
     •-- Test for space or tab.
     If (C <> " " And C <> vbTab) Then
     &#8226;-- Neither space nor tab.
     &#8226;-- Test if already in argument.
     If Not InArg Then
     &#8226;-- New argument begins.
     &#8226;-- Test for too many arguments.
     If ArgNum = NumberOfArguments Then Exit For
     ArgNum = ArgNum + 1
     InArg = True
     End If
     &#8226;-- Concatenate character to current argument.
     ArgArray(ArgNum) = ArgArray(ArgNum) & C
     Else
     &#8226;-- Found a space or tab.
     &#8226;-- Set InArg flag to False.
     InArg = False
     End If
     End If
     Next I
     &#8226;-- Resize array just enough to hold arguments.
     ReDim Preserve ArgArray(ArgNum)
     &#8226;-- Return Array in Function name.
     GetCommandLine = ArgArray()
    End Function
 


Download this snippet    Add to My Saved Code

How to implement command-line parameters in Visual Basic Comments

No comments have been posted about How to implement command-line parameters in Visual Basic. Why not be the first to post a comment about How to implement command-line parameters in Visual Basic.

Post your comment

Subject:
Message:
0/1000 characters