argument question

  • Thread starter Thread starter romy
  • Start date Start date
R

romy

Hi


How do I use external argument in vb.net ?

for example I want to open a form by its argument

myprog.exe 1 -> open form1
myprog.exe 2 -> open form2.
.....
 
How do I use external argument in vb.net ?

Something like this:

Shared Sub Main(ByVal args() As String)

Dim f As Form
If args(0) = "1" Then
f = New Form1
ElseIf args(0) = "2" Then
f = New Form2
End If
Application.Run(f)

End Sub



Mattias
 
romy said:
How do I use external argument in vb.net ?

for example I want to open a form by its argument

myprog.exe 1 -> open form1
myprog.exe 2 -> open form2.

\\\
Public Module Program
Public Sub Main(ByVal Args() As String)
If Args.Length > 0 Then
Dim MainForm As Form
Select Case Args(0)
Case "1"
MainForm = New Form1()
Case "2"
MainForm = New Form2()
Case Else
Return
End Select
Application.Run(MainForm)
End If
End Sub
End Module
///

Don't forget to select 'Sub Main' as startup object in the project
properties dialog.
 
Hi,

In addition to Mattias & Herfried, you can access command line arguments
outside Main() by Shared Environment.CommandLine and
Environment.GetCommandLineArgs().

Roman
 

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

Back
Top