473,387 Members | 1,575 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Get parameters in Console App

Hello,

I'm wroting a console utility in VB 2005, and I need the ability to pass
parameters to the application when the program runs. For example, if my
program is called testing.exe, I need to be able to run this:

c:\testing.exe c:\test

....and have 'c:\test' passed to the program as a variable. Most of my VB
books focus on web forms or windows forms, but not much details on console
applications. Any suggestions or resources showing this?

Thanks --

Alex
Sep 13 '07 #1
3 10089
On Sep 13, 9:10 am, "Alex" <sama...@gmail.comwrote:
Hello,

I'm wroting a console utility in VB 2005, and I need the ability to pass
parameters to the application when the program runs. For example, if my
program is called testing.exe, I need to be able to run this:

c:\testing.exe c:\test

...and have 'c:\test' passed to the program as a variable. Most of my VB
books focus on web forms or windows forms, but not much details on console
applications. Any suggestions or resources showing this?

Thanks --

Alex
You can add an "args" parameter to the sub main method and retrieve
the arguments.

i.e.
////////////////////
Module Module1

Sub Main(ByVal args() As String)
For Each s As String In args
Console.WriteLine(s)
Next

Console.WriteLine("All arguments printed")

Console.Read()
End Sub

End Module
///////////////////

Also, in case you didn't know, you can set command line parameters for
debugging by going to the Debug tab of the project properties form.

Thanks,

Seth Rowe

Sep 13 '07 #2
"rowe_newsgroups" <ro********@yahoo.comwrote in message
news:11**********************@d55g2000hsg.googlegr oups.com...
On Sep 13, 9:10 am, "Alex" <sama...@gmail.comwrote:
>Hello,

I'm wroting a console utility in VB 2005, and I need the ability to pass
parameters to the application when the program runs. For example, if my
program is called testing.exe, I need to be able to run this:

c:\testing.exe c:\test

...and have 'c:\test' passed to the program as a variable. Most of my VB
books focus on web forms or windows forms, but not much details on
console
applications. Any suggestions or resources showing this?

Thanks --

Alex

You can add an "args" parameter to the sub main method and retrieve
the arguments.

i.e.
////////////////////
Module Module1

Sub Main(ByVal args() As String)
For Each s As String In args
Console.WriteLine(s)
Next

Console.WriteLine("All arguments printed")

Console.Read()
End Sub

End Module
///////////////////

Also, in case you didn't know, you can set command line parameters for
debugging by going to the Debug tab of the project properties form.

Thanks,

Seth Rowe
Hi Seth,

This is exactly what I was hunting for ... thanks. also can you or someone
else suggest a good book or resource on coding console applications with VB?
Most books start with creating a Hello World app for Console, but I'd like
to start writing some corporate utilities which we can run in login scripts
and schedule in Tast Scheduler. I'm not however finding any good books or
references focusing on console apps (as opposed to web/win forms).

Thanks again --

Alex
Sep 13 '07 #3
On Sep 13, 11:54 am, "Alex" <sama...@gmail.comwrote:
"rowe_newsgroups" <rowe_em...@yahoo.comwrote in message

news:11**********************@d55g2000hsg.googlegr oups.com...
On Sep 13, 9:10 am, "Alex" <sama...@gmail.comwrote:
Hello,
I'm wroting a console utility in VB 2005, and I need the ability to pass
parameters to the application when the program runs. For example, if my
program is called testing.exe, I need to be able to run this:
c:\testing.exe c:\test
...and have 'c:\test' passed to the program as a variable. Most of my VB
books focus on web forms or windows forms, but not much details on
console
applications. Any suggestions or resources showing this?
Thanks --
Alex
You can add an "args" parameter to the sub main method and retrieve
the arguments.
i.e.
////////////////////
Module Module1
Sub Main(ByVal args() As String)
For Each s As String In args
Console.WriteLine(s)
Next
Console.WriteLine("All arguments printed")
Console.Read()
End Sub
End Module
///////////////////
Also, in case you didn't know, you can set command line parameters for
debugging by going to the Debug tab of the project properties form.
Thanks,
Seth Rowe

Hi Seth,

This is exactly what I was hunting for ... thanks. also can you or someone
else suggest a good book or resource on coding console applications with VB?
Most books start with creating a Hello World app for Console, but I'd like
to start writing some corporate utilities which we can run in login scripts
and schedule in Tast Scheduler. I'm not however finding any good books or
references focusing on console apps (as opposed to web/win forms).

Thanks again --

Alex
You'll have to rely on the "someone else" for that question. I haven't
read very many of the VB books that are out there, and all the one's
I've seen are mostly about win forms and ASP.NET. You might have some
luck with the .Net Framework books which are more about the framework
features and not the development style.

However, most things programming wise are going to be the same - the
main difference is how you get your information from the user. In most
console applications the user has very little control over what
happens after they start the program, any input is done mostly in the
form of command line arguments. If you stick to narrow-tasked console
apps that get all necessary input from the command line arguments you
should be able to rely on just your knowledge of the framework and
it's classes to get the job(s) done.

As always, if you hit a snag you can always post here and we will
(hopefully) be able to help you out. All we ask is that before posting
you do some searching on google or the newsgroup archives to see if
the question has already been answered. The archives are located at:

http://groups.google.com/group/micro...b?lnk=sg&hl=en

Thanks,

Seth Rowe

Sep 13 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Andy | last post by:
Hi Could someone clarify for me the method parameter passing concept? As I understand it, if you pass a variable without the "ref" syntax then it gets passed as a copy. If you pass a...
1
by: Michael Hetrick | last post by:
How would I pass parameters to a console application? I would like to do something like this: consoleapp.exe /o \\fileshare\origindirectory /d \\fileshare\destinationdirectory I'm not sure...
8
by: A.M | last post by:
Hi, Are string parameters in functions by refrence or by value ? Thanks, Ali
16
by: ad | last post by:
Does C#2.0 support optional parameters like VB.NET: Function MyFunction(Optional ByVal isCenter As Boolean = False)
3
by: SamoK | last post by:
Hy! I'd like to know how can I use ref and out parameters in c++. I'd like to send (from C#) to my C++.net function a variable by reference, so I could change it in my c++.net function. And...
1
by: kplkumar | last post by:
I am trying to get the method and the parameters passed to that method from the stackTrace. My code is, private void GetExecutingMethodInfo() { StackTrace trace = new StackTrace(false); ...
2
by: DaveL | last post by:
Hello I want to build Dynamic Paramers for a Sql Insert below is what i have so far but...determinthe column type and length im having Problems with Tks dave string sInsert = "Insert into...
7
by: =?Utf-8?B?UGFvbG8=?= | last post by:
I have the following: void setColours() { Console.BackgroundColor = ConsoleColor .Black; Console.ForegroundColor = ConsoleColor.Yellow; } thus setting the colours at compile time.
3
by: kpeeroo | last post by:
Private Function AddCompanyOvertime() As Integer Dim companyID As Integer = GetCompanyID() Console.WriteLine(companyID) Dim paramCompanyID As New SqlParameter("@CompanyID",...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.