accepting command line parameters into a vb.net 2005 app...

B

Brad Pears

I want to pass an integer customer# into my vb app from the command line
when I run it... something like this....

c:\program files\Myapp\myvbapp.exe 100

So in the case above, when my applciation "myvbapp.exe" runs, I want to read
in the integer parameter 100 (cust#) and use that value in my code to
load up the appropriate data for cust# 100.

How can this be accomplished in vb.net 2005??

Thanks, Brad
 
R

rowe_newsgroups

I want to pass an integer customer# into my vb app from the command line
when I run it... something like this....

c:\program files\Myapp\myvbapp.exe 100

So in the case above, when my applciation "myvbapp.exe" runs, I want to read
in the integer parameter 100 (cust#) and use that value in my code to
load up the appropriate data for cust# 100.

How can this be accomplished in vb.net 2005??

Thanks, Brad

Declare the following Sub Main and set it as the start object:

Public Sub Main(args() as String)
' Pull the commandline arguments out of the args() variable

End Sub

Note, if this is a Windows Application you may need to disable the
application framework and initialize everything manually in the sub
main.

Thanks,

Seth Rowe
 
K

kmoorman

Brad,

The 2 easiest ways are:

My.Application.CommandLineArgs

Visual Basic's Command function

Kerry Moorman
 
Z

zacks

I want to pass an integer customer# into my vb app from the command line
when I run it... something like this....

c:\program files\Myapp\myvbapp.exe 100

So in the case above, when my applciation "myvbapp.exe" runs, I want to read
in the integer parameter 100 (cust#) and use that value in my code to
load up the appropriate data for cust# 100.

How can this be accomplished in vb.net 2005??

Thanks, Brad

There is also a special variable accessible to your code named Command
$. It is a character string that contains the command line. You can
split it up like this:

Dim Args() as String

Args = Split(Command$, " ")
 
B

Brad Pears

Thanks for that...

It is a .vb.net 2005 windows application. I am not quite sure what you mean
by "disabling the applicaiton framework and initialize everything manually
in the sub main". Why would I have to do this and what exactly is this?

Can you be more specific??

Thanks , Brad
 
R

rowe_newsgroups

Thanks for that...

It is a .vb.net 2005 windows application. I am not quite sure what you mean
by "disabling the applicaiton framework and initialize everything manually
in the sub main". Why would I have to do this and what exactly is this?

Can you be more specific??

Thanks , Brad

Just try setting your startup object as Sub Main and you'll see what I
mean. With the "Enable Application Framework" enabled you can only
select a form as your starting object. So to use Sub Main as a start
point you'll need to show the main form manually after you process the
command line arguments. (You might also want to call
Application.EnableVisualStyles to get the XP style controls back).

Thanks,

Seth Rowe
 
Z

zacks

Thanks for that...

It is a .vb.net 2005 windows application. I am not quite sure what you mean
by "disabling the applicaiton framework and initialize everything manually
in the sub main". Why would I have to do this and what exactly is this?

Can you be more specific??

Thanks , Brad

Open My Project. Go to the Application tab. Turn off the Enable
application framework click box. That will let you change the Startup
object dropdown. Select your Main module. In the Main module be sure
to include the line:

Application.EnableVisualStyles()
 
B

Brad Pears

Thanks for that!!!
Look easy enough!

Brad
There is also a special variable accessible to your code named Command
$. It is a character string that contains the command line. You can
split it up like this:

Dim Args() as String

Args = Split(Command$, " ")
 
B

Brad Pears

Ok, I understand. I was thinking there was something way more involved!!!

Thanks for your help!!
Brad
 

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