Click to See Complete Forum and Search --> : parameter in Command Line
August 24th, 1999, 02:22 PM
Hi
I have a VB application and I want it to read a parameter from command line when starts. That is, in command line, if I type in:"AppName ParamValue...", the VB applciation should be able to get "ParamValue". Does anybody know how to do it?
Thanks a lot for any help.
August 24th, 1999, 04:50 PM
I believe the Command function is precisely what you desire, as in
Dim cmdLineArgs as string
cmdLineArgs = Command
Peter Gloor
August 27th, 1999, 02:48 PM
Function GetCommandLine(optional MaxArgs)
'Declare variables.
Dim C, CmdLine, CmdLnLen, InArg, I, NumArgs
'See if MaxArgs was provided.
If IsMissing(MaxArgs) then MaxArgs = 10
'Make array of the correct size.
ReDim ArgArray(MaxArgs)
NumArgs = 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
'Neither space nor tab.
'Test if already in argument.
If Not InArg then
'new argument begins.
'Test for too many arguments.
If NumArgs = MaxArgs then Exit for
NumArgs = NumArgs + 1
InArg = true
End If
'Concatenate character to current argument.
ArgArray(NumArgs) = ArgArray(NumArgs) & C
else
'Found a space or tab.
'set InArg flag to false.
InArg = false
End If
next I
'Resize array just enough to hold arguments.
ReDim Preserve ArgArray(NumArgs)
'Return Array in Function name.
GetCommandLine = ArgArray()
End Function
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.