By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,779 Members | 1,309 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,779 IT Pros & Developers. It's quick & easy.

Get parameters in Console App

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
"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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.