Passing arguments to your VB.NET console application

Posted by Daniel - 2,802 Views

console application,vb.net,cli,command line interface,passing argument to vb.net,command line parameterA 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:

Dim arrArgs() As String = Command.Split(“,”)

Lets say the name of your application is “myApp”. If you run it with this syntax below:

> myApp "Hello","World"

Then the arrArgs array will contains these element:

arrArgs(0) = "Hello"
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:

Sub Main()
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.

__________________________

Related posts brought to you by Yet Another Related Posts Plugin.

share this article

Digg del.icio.us Netscape StumbleUpon Yahoo! MyWeb reddit Furl Magnolia Newsvine Technorati SlashDot Blinklist Simpy Google
This post as PDFPosted in: Programming - January 2008


Leave a Reply


Options for your comment:





Get my Full Feed Here or you can subscribe to one of my category based feeds below:
Coffee Break

Latest Blog Entries

Categories

Neighbours and Friends

Login Here

Comments - Thanks Guys :)

  • Coarveadvexon: As the call, so the echo :D Coarveadvexon’s last blog post: Ford Kuga 2.5 Turbo
  • Chat: nice thank you very much for this article.
  • a_suliman: thanx for every thing
  • Miss Lunatic: Jaja, it’s a yolk. Thanks for the compliment ;) Miss Lunatic’s last blog post: Pitas y guacamole
  • Miss Lunatic: Thank you! Your style css is awesome. I’m going to start customizing with it. Thank you :D Miss Lunatic’s last blog...