Get parameters in Console App

A

Alex

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
 
R

rowe_newsgroups

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
 
A

Alex

rowe_newsgroups said:
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
 
R

rowe_newsgroups

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/microsoft.public.dotnet.languages.vb?lnk=sg&hl=en

Thanks,

Seth Rowe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top