How the get the parameter???

  • Thread starter Thread starter zurg
  • Start date Start date
Z

zurg

I need to get information with what parameter a VB.NET application was
started?
For example I run a application like this:
"c:\myapp.exe 200"
Is there any way to get this number and for example do in application:
MsgBox(whatyouget)? And it should show MsgBox with "200"

It should be very easy (I hope;))
Please answer as fast as you can - I really need that...

Thanks in advance,
zurg
 
zurg said:
I need to get information with what parameter a VB.NET application
was started?
For example I run a application like this:
"c:\myapp.exe 200"
Is there any way to get this number and for example do in
application: MsgBox(whatyouget)? And it should show MsgBox with
"200"

It should be very easy (I hope;))
Please answer as fast as you can - I really need that...

Microsoft.VisualBasic.Interaction.Command
System.Environment.GetCommandLineArgs

Or

Shared sub Main(args as string())
End Sub
 
Zurg,
There are a number of ways to do this.

Add parameters to your Sub Main, valid forms of Main include:

Public Sub Main()
Public Sub Main(ByVal args() as String)
Public Function Main() As Integer
Public Function Main(ByVal args() as String) As Integer

The args parameter above is the list of parameters passed to your program.
The Function Main allow you to return a return code that can be checked by
batch files & other programs.

Alternatively you can use:

System.Environment.CommandLine
System.Environment.GetCommandLineArgs

The first is a string property you need to parse, the second is a function
that returns an array of string. Both are shared members, so you do not need
to create an Environment variable.

Hope this helps
Jay
 
Module Module1

' the "official" entry point
Sub Main()
' call the Main with arguments
Main(Environment.GetCommandLineArgs())
End Sub

' the "real" Main procedure
Private Sub Main(ByVal args() As String)
' suppose that we expect two arguments, but there is always an
' extra argument that contains the EXE filename
If args Is Nothing OrElse args.Length <> 3 Then
Console.WriteLine("Syntax error.")
Else
' use the arguments args(1) and args(2)
' ...
End If
End Sub

End Module

I need to get information with what parameter a VB.NET application was
started?
For example I run a application like this:
"c:\myapp.exe 200"
Is there any way to get this number and for example do in application:
MsgBox(whatyouget)? And it should show MsgBox with "200"

It should be very easy (I hope;))
Please answer as fast as you can - I really need that...

Thanks in advance,
zurg

Best Regards - OHMBest Regards - OHM (e-mail address removed)
 
Note ** You cac specify the command line parameter in the Project Options !

here's another little example . .

Sub Main(ByVal args() As String)

Dim i As Int32

For i = 0 To args.Length - 1

Console.WriteLine(args(i))

Next

Console.ReadLine()

End Sub


I need to get information with what parameter a VB.NET application was
started?
For example I run a application like this:
"c:\myapp.exe 200"
Is there any way to get this number and for example do in application:
MsgBox(whatyouget)? And it should show MsgBox with "200"

It should be very easy (I hope;))
Please answer as fast as you can - I really need that...

Thanks in advance,
zurg

Best Regards - OHMBest Regards - OHM (e-mail address removed)
 
Back
Top