Jump to content

Recommended Posts

Posted

Hey,

 

So I was just playing around with visual studio, creating windows forms, and I was wondering if any one knows if you can set cmd switches like you can with batch files. I know in a batch file you can run it using C:\filepath\batchfile.bat switch1 switch2 and then use those in the batch file as %1 and %2. Is there a similar thing with visual studio executables? Like say if i created a shortcut that pointed to the exe with some switches on it, and have those switches autofill some text boxes type of thing? Is there a variable name that you can use for switches?

Posted
ah yeah sorry, i forget you can use other languages in visual studio, but yeah if i do something like If Environment.GetCommandLineArgs("variable1") Then would that check that an argument is called variable1? and the go to the if statement?
Posted

You'd be looking at something like the following:

Dim input1 As String

 'Check if there are any command line arguments.
 If Environment.GetCommandLineArgs.Length > 1 Then

 'Get the command line argument at the second position (in Visual Studio, the first position '0' is taken up by 
 'the EXE's location - you'll need to check if this is the case in a finished program, I can't remember)
 input1 = Environment.GetCommandLineArgs(1)

 'Compare the input to a string. Uses 'ToLower' to ignore capitalisation.
 'A SELECT/CASE statement could be used if you expect multiple arguments. If you could expect multiple arguments
 'and aren't sure of the order they'll be in, it might be worth passing these to a function to process, then returning 
 'a variable for each option.
 If input1.ToLower = "option1" Then   

  'PROGRAM CODE HERE

 End If
 'OTHER OPTIONS HERE (duplicate above IF, or convert to SELECT/CASE if it's worthwhile)
End If

 

I hope that this helps you in the right direction :)

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...