|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Receiving a system parameter at program launch in VB6
Is there a function in VB6 to retrieve a command line parameter passed to a VB application at launch?
For example, if I have a program named quiz.exe, and launch it from a run line with a parameter, for example quiz.exe /reset what function can I use within the program to capture the "/reset" and assign it to a variable? Some example code would be helpful, and most appreciated. Thanks |
|
#2
|
|||
|
|||
|
|
|
#3
|
|||
|
|||
|
In the msdn web site:
Command Function: Returns the argument portion of the command line used to launch Microsoft Visual Basic or an executable program developed with Visual Basic. Syntax Command Remarks When Visual Basic is launched from the command line, any portion of the command line that follows /cmd is passed to the program as the command-line argument. In the following example, cmdlineargs represents the argument information returned by the Command function. VB /cmd cmdlineargs For applications developed with Visual Basic and compiled to an .exe file, Command returns any arguments that appear after the name of the application on the command line. For example: MyApp cmdlineargs To find how command line arguments can be changed in the user interface of the application you're using, search Help for "command line arguments." This example uses the Command function to get the command line arguments in a function that returns them in a Variant containing an array. 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 |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Visual Basic Programming > Receiving a system parameter at program launch in VB6 |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|