Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Command line arguments (I think)

Status
Not open for further replies.

JonathonC

Technical User
Aug 18, 2001
43
GB
I'm not sure if that's what it's called, but what I want is to have an extra peice of writting at the end of the 'Target' part of a shortcut. Then when the shortcut is double clicked on my program will open and do a certain thing. If the shortcut does not contai the extra writting then it will just function as normal. How would I do this?

Thanks,
Jonathon. Computer problems? Have you checked the loose nut in front of the keyboard yet?
 
check out the Command() function
check the return value on your program's startup module/form

ex.
Code:
sub main() ' or from Private Sub Form_Load()
 if Command()="-v" then
   msgbox "ver." & app.major & "." & app.minor
 else
   ' process normally here
 endif
end sub

example from MSDN:

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 <> &quot; &quot; 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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top