Creat exe that accepts parameter and acts accordingly

johann

New member
Joined
Mar 27, 2007
Messages
2
Programming Experience
Beginner
Hi,

I am creating an extremely simple application that simply sends a character down the serial port to a electronic switch to make it switch back and forth.

At the moment I have the communication between application and serial port working good by means of clicking 2 buttons on a form making it switch back and forth.

Now I need to take it to the next level. My application gets called by another application and is passed a parameter to tell it to open, switch and close

It is called in this way:

TriggerExternalSwitch.exe 1 (Switch to channel 1)
TriggerExternalSwitch.exe 2 (Switch to channel 2)

How do I make the application to expect a parameter when called and act accordingly?

I appologise if its a newbie question but Im not a coder for a living :)
 
Environment.GetCommandLineArgs returns an array of strings where first item is the app path and rest is space separated paramters. (you can doublequote a parameter to keep it one item including spaces also)

Edit: a little late submit here after Android, but some more info also. ;)
 
VB.NET:
for each argument as string in Environment.GetCommandLineArgs()
msgbox(argument)
next
 
or:
VB.NET:
For Each str As String in Environment.GetCommandLineArgs()
  Select Case str
    Case "1"
      'Code for the switch to channel 1
    Case "2"
      'Code for the switch to channel 2
    Case Else
      'Code for invalid command arg
Next str
 
Back
Top