argument question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • romy

    #1

    argument question

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


  • Mattias Sjögren

    #2
    Re: argument question

    >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

    --
    Mattias Sjögren [MVP] mattias @ mvps.org
    http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
    Please reply only to the newsgroup.

    Comment

    • Herfried K. Wagner [MVP]

      #3
      Re: argument question

      "romy" <romy1000@hotpo p.com> schrieb:[color=blue]
      > 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.[/color]

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

      --
      M S Herfried K. Wagner
      M V P <URL:http://dotnet.mvps.org/>
      V B <URL:http://classicvb.org/petition/>

      Comment

      • Dragon

        #4
        Re: argument question

        Hi,

        In addition to Mattias & Herfried, you can access command line arguments
        outside Main() by Shared Environment.Com mandLine and
        Environment.Get CommandLineArgs ().

        Roman
        "romy" <romy1000@hotpo p.com> ñîîáùèë/ñîîáùèëà â íîâîñòÿõ ñëåäóþùåå:
        news:OBsES6zmFH A.860@TK2MSFTNG P12.phx.gbl...[color=blue]
        > 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.
        > ....
        >
        >[/color]


        Comment

        Working...