• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 182
  • Last Modified:

Recieving parameters on the command line

I'm trying to program a very elementary program (to work with another software vendors program) that needs to be able to accept two parameters from the command line.  

The instructions I have from the software vendor say: When [TheirSoftware] 'calls' or invokes [MyProgram], it passes two parameters on the command line.  The first parameter is the exact name and path of the [first text file generated by TheirSoftware] and the second paraemter is the exact name and path of the [text file to be passed back to TheirSoftware].

So my program will be invoked like this:

MyProgram c:\somedirectory\original.txt c:\somedirectory\new.txt

How do I read or use the parameters that are being passed to MyProgram?
0
HKComputer
Asked:
HKComputer
3 Solutions
 
appariCommented:
add a Main sub in a module as follows

      Sub main(ByVal ParamArray args() As String)

       
      end sub

now you will get all the command line arguments in the array args. set this sub main as your startup object
0
 
Naveen SwamyCommented:
Returns the argument portion of the command line used to start Visual Basic or an executable program developed with Visual Basic. The My feature provides greater productivity and performance than the Command function. For more information, check out My.Application.CommandLineArgs Property.

Function GetCommandLineArgs() As String()
   ' Declare variables.
   Dim separators As String = " "
   Dim commands As String = Microsoft.VisualBasic.Interaction.Command()
   Dim args() As String = commands.Split(separators.ToCharArray)
   Return args
End Function

0
 
tolgaongCommented:
Environment.GetCommandLineArgs
this will return the parameters as a string array
so:

dim CLP as string() = Environment.GetCommandLineArgs()
first element is always your programs name with full path
and the others are the parameters youhave sent

MyProgram c:\somedirectory\original.txt c:\somedirectory\new.txt

if you have spaces in the parameters
MyProgram c:\some directory\original.txt c:\some directory\new.txt

you should identify the parameters with quetation markas
MyProgram "c:\some directory\original.txt" "c:\some directory\new.txt"
0
 
HKComputerAuthor Commented:
I believe that all three of the above answers are correct.  I found the last one the easiest to understand and therefore I used it.  Thanks for you help.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now