Passing Arguments at run-time

R

Ricky W. Hunt

First, I apologize for asking so many questions. General programming terms
must have changed so much in the last 10 years since I've been out of it
because I can't seem to find ANYTHING in MS's help file if I don't have a
keyword to start with.

I'm looking for a way to pass an argument to the EXE at runtime so I can
branch to different things inside the program depending on what I pass it.
For instance in the desktop shortcut under target I'd like to be able to
put:

"program.exe" 1

to pass the integer 1 into the program, etc.

Can someone point me to the right way (if this is possible).


Here's the code I came up with (not sure if it's right): New is my "main"
entry point

Public Sub New(Optional ByVal arg1 As Integer = 0)

MyBase.New()

'This call is required by the Windows Form Designer.

InitializeComponent()

'Add any initialization after the InitializeComponent() call

InitDirectSound()

Randomize()



'If HideDisplay = 1 Then

If arg1 = 1 Then

lblFreq.Visible = False

lblGain.Visible = False

Label4.Visible = False

Label3.Visible = False

End If

End Sub
 
G

Greg Burns

Here is one way:

Dim arg As String
For Each arg In Environment.GetCommandLineArgs
Debug.WriteLine(arg)
Next

OR

Public Sub Main(ByVal args As String( ))
End Sub

Also see link for passing to Sub New...

http://tinyurl.com/46j2y

HTH,
Greg
 
J

Jeff Johnson [MVP: VB]

First, I apologize for asking so many questions. General programming terms
must have changed so much in the last 10 years since I've been out of it
because I can't seem to find ANYTHING in MS's help file if I don't have a
keyword to start with.

I'm looking for a way to pass an argument to the EXE at runtime so I can
branch to different things inside the program depending on what I pass it.

As far as keywords go, these are generally referred to as "command line
parameters."
 
C

Chris Dunaway

As far as keywords go, these are generally referred to as "command line
parameters."

And it hasn't changed in 10 years. It's been called the command line since
the DOS days.

--
Chris

dunawayc[AT]sbcglobal_lunchmeat_[DOT]net

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
 
H

Howard Kaikow

And prior to the DOS daze.

But remember, PC means "Plug Compatible".

--
http://www.standards.com/; See Howard Kaikow's web site.
Chris Dunaway said:
it

As far as keywords go, these are generally referred to as "command line
parameters."

And it hasn't changed in 10 years. It's been called the command line since
the DOS days.

--
Chris

dunawayc[AT]sbcglobal_lunchmeat_[DOT]net

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
 

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