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

Passing Arguments at run-time

P: n/a
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
--
Thanks,
Ricky W. Hunt
freendeed
Nov 20 '05 #1
Share this Question
Share on Google+
6 Replies


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

"Ricky W. Hunt" <rh*****@hotmail.com> wrote in message
news:vFFLc.159769$XM6.113142@attbi_s53...
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
--
Thanks,
Ricky W. Hunt
freendeed

Nov 20 '05 #2

P: n/a
"Greg Burns" <greg_burns@DONT_SPAM_ME_hotmail.com> wrote in message
news:OB**************@TK2MSFTNGP12.phx.gbl...
Here is one way:

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


That worked. Thanks.
Nov 20 '05 #3

P: n/a

"Ricky W. Hunt" <rh*****@hotmail.com> wrote in message
news:vFFLc.159769$XM6.113142@attbi_s53...
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."
Nov 20 '05 #4

P: n/a
On Thu, 22 Jul 2004 08:55:01 -0400, Jeff Johnson [MVP: VB] wrote:

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


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.
Nov 20 '05 #5

P: n/a
Hi Chris,

You mean MS Dos I assume?

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


:-)

Cor
Nov 20 '05 #6

P: n/a
And prior to the DOS daze.

But remember, PC means "Plug Compatible".

--
http://www.standards.com/; See Howard Kaikow's web site.
"Chris Dunaway" <"dunawayc[[at]_lunchmeat_sbcglobal[dot]]net"> wrote in
message news:1l*****************************@40tude.net...
On Thu, 22 Jul 2004 08:55:01 -0400, Jeff Johnson [MVP: VB] wrote:

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
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.

Nov 20 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.