Link to home
Start Free TrialLog in
Avatar of fibdev
fibdev

asked on

Accepting command arguments

I've recently created an application and then decided I wanted to use shell extentions to enhance it.  I know about creating the shell extentions.  My question is this.  How can I have my app accept command arguments when it is called to load.  Example:  I want to right-click on an executable and choose a menu item that launches my application.  When my application loads, I want it to know the size of the file that I right-clicked on.
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Use the Command function.

This is the example taken from the help file:

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

Avatar of telebasics
telebasics

Yes, in the Command function are all param's given to your prog. When you right click a file and select you prog menu item, make sure you open it with %1 param then the selected filename is passed, open it and with LOF(fn) you get the size (easy example)
Avatar of fibdev

ASKER

telebasics,

could you please elaborate on how to do this?  LOF(fn)?

Thanks
ASKER CERTIFIED SOLUTION
Avatar of telebasics
telebasics

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial