Passing arguments to your VB.NET console application
Posted by Daniel - 117,571 Views
A console application or a command line interface or CLI is a method of interacting with a computer via a text terminal. Commands are entered as lines of text (that is, sequences of typed characters) from a keyboard, and output is also received as text -wikipedia.org
To create a new console application project with Visual Basic.NET, choose File - New - Project. On the next dialog that appears, select Visual Basic Projects from the Project Types treeview then select Console Application icon from the Templates listview. Fill the project detail such as name and location then hit OK. A new module named Module1 will be created after that.
Inside the newly created module, there is a Sub procedure called Main(). This is the startup object of your console application, where you write your program code.
We will create a simple VB.NET console application which may accepts CLI parameters separated by commas. Below is the line that initiated an array to hold the parameters passed to the application:
Lets say the name of your application is “myApp”. If you run it with this syntax below:
Then the arrArgs array will contains these element:
arrArgs(1) = "World"
What you are going to do next with those values is up to you. Following is the Sub Main() full code you can use to test it:
Dim arrArgs() A s String = Command.Split(“,”)
Dim i As Integer
Console.Write(vbNewLine & vbNewLine)
If arrArgs(0) <> Nothing Then
For i = LBound(arrArgs) To UBound(arrArgs)
Console.Write(“Parameter “ & i & ” is “ & arrArgs(i) & vbNewLine)
Next
Else
Console.Write(“No parameter passed”)
End If
Console.Write(vbNewLine & vbNewLine)
End Sub
That code will accept parrameters passed to the EXE then it will display the accepted parameters to the monitor.
The following posts are programmatically considered as related to the current post by YARPP Plugin:
- ConsoleProgressBar - Simple Progress Bar Function for your VB.Net Console Application
- How to Get User Input and allowing more than 256 characters to be entered on .NET Console Application
- Runtime-Form-Creation. Automatically creating child forms in a Delphi MDI application with a component array
- Visual Basic.NET, an example of using HTTPWebRequest object
- Resizing image on the fly with ASP.NET using the System.Drawing namespace
Hi, my name is Daniel Nugraha, a single male live on an island called Java, Indonesia. This is the place for me to share my interest in computer programming.
-
Get my Full Feed Here
Popular Entries
- Passing arguments to your VB.NET console application
- Microsoft Excel Import External Data Problem: When Microsoft Query doesn’t recognize some of your parameters
- Resize Image or Crop Image with Joe Lencioni’s Smart Image Resizer, WordPress Setup
- How to Get User Input and allowing more than 256 characters to be entered on .NET Console Application
- ASCII To PDU Converter (Convert ASCII to PDU and vice versa)
- ConsoleProgressBar - Simple Progress Bar Function for your VB.Net Console Application
- An example: Using CPort Delphi Component to read data from your cellphone
- Runtime-Form-Creation. Automatically creating child forms in a Delphi MDI application with a component array
- CPort Component (Serial port interface component for Delphi)
- SmartImageResizer Plugin, WordPress plugin based on Joe Lencioni’s Smart Image Resizer













