Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get arguments of Main method in VB.NET

Tags:

vb.net

In C# Console Application, Main method has a string() argument, but in VB.NET, the Main method doesn't contain the argument, if I set command line arguments, how to retrieve them?

In C#, if I right click the project and select Properties, set command line arguments in debug item, I can use args[0], args[1] and so on to achive my arguments. In VB.NET, I found

System.Environment.GetCommandLineArgs()

can also achive them, but it contains one more argument, it also contains the path of the process, anyone can help?

like image 265
James Avatar asked Oct 08 '12 10:10

James


People also ask

How do I find command line arguments in Visual Studio?

To set command-line arguments in Visual Studio, right click on the project name, then go to Properties. In the Properties Pane, go to "Debugging", and in this pane is a line for "Command-line arguments." Add the values you would like to use on this line.

What are arguments in VB net?

An argument represents the value that you pass to a procedure parameter when you call the procedure. The calling code supplies the arguments when it calls the procedure. When you call a Function or Sub procedure, you include an argument list in parentheses immediately following the procedure name.

What is the purpose of arguments in main method?

The arguments passed to the main method in C come from the command line when you execute the program. You add them when you use the command line arguments as the mechanism for passing input information from the user to the program. The program could still work if you have no command line arguments and passed nothing.


1 Answers

You could add them to the entry point method signature (ByVal args() As String) and access them just as you would in C#. You could also use VB.NETs My class to access them such as My.Application.CommandLineArgs.

like image 193
Grant Thomas Avatar answered Oct 03 '22 14:10

Grant Thomas