|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
|||
|
|||
|
Passing params to an exe
I have a VB.Net Form exe application, which I wish to optionally pass command line arguments to.
How can I change the .exe so that if it is run with some parameters from the command prompt, it will process these and perhaps therefore not having to launch the form as per usual? |
|
#2
|
|||
|
|||
|
Use the Command function
Function GetCommandLineArgs() As String()
' Declare variables. Dim separators As String = " " Dim commands As String = Microsoft.VisualBasic.Command() Dim args() As String = commands.Split(separators.ToCharArray) Return args End Function |
|
#3
|
|||
|
|||
|
How would I go about doing the same thing in vb 6?
|
|
#4
|
|||
|
|||
|
i think you use command or vba.command...
in .net you can also define a main() entry point with an array of string arguments passed and, if you want, a return value. Last edited by epl : July 29th, 2003 at 07:51 AM. |
|
#5
|
||||
|
||||
|
For VB6 you would use Command()
Here is a sample from the MSDN library: Code:
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
|
|
#6
|
|||
|
|||
|
Thanks
Worked like a charm. I hate it when I forget simple things like that ![]() |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Visual Basic Programming > Passing params to an exe |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|