Application Parameters

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?U2VyZ2lv?=

    Application Parameters

    I need to pass two parameter to a vb.net 2003 windows form application, is
    this posible? how?
  • Tom Shelton

    #2
    Re: Application Parameters

    On 2008-04-21, Sergio <Sergio@discuss ions.microsoft. comwrote:
    I need to pass two parameter to a vb.net 2003 windows form application, is
    this posible? how?
    Sure... You either use one of the overloaded versions of sub main:

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

    or...

    You can get teh command line arguments from
    System.Environm ent.GetCommandL ineArgs or
    System.Environm ent.CommandLine . Oh, yeah VB also has the
    My.Application. CommandLineArgs property as well as the old VB Command
    function. I believe that the My.Application. CommandLineArgs is the
    recommended way now :)

    --
    Tom Shelton

    Comment

    • Cor Ligthert[MVP]

      #3
      Re: Application Parameters

      Tom,
      My.Application. CommandLineArgs property as well as the old VB Command
      function. I believe that the My.Application. CommandLineArgs is the
      recommended way now :)
      \
      Why?

      In my idea is the My class only build to make it easier for old VB6 users.
      That does in my idea not make it the recommended way.

      The overloaded constructor is in my idea the normal way for this.

      Cor

      Comment

      • kimiraikkonen

        #4
        Re: Application Parameters

        On Apr 22, 12:18 am, Sergio <Ser...@discuss ions.microsoft. comwrote:
        I need to pass two parameter to a vb.net 2003 windows form application, is
        this posible? how?
        Sergio,
        You can launch your application with passing parameters using.
        Generally, the parameters are passed when form's load event is fired.
        So you can do;

        You can get all the parameters that are passed on application startup;

        Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
        System.EventArg s) Handles MyBase.Load
        For Each x As String In Environment.Get CommandLineArgs
        MsgBox(x)
        Next
        End Sub

        Hope this helps,

        Onur

        Comment

        • Tom Shelton

          #5
          Re: Application Parameters

          On 2008-04-22, Cor Ligthert[MVP] <notmyfirstname @planet.nlwrote :
          Tom,
          >
          >My.Application .CommandLineArg s property as well as the old VB Command
          >function. I believe that the My.Application. CommandLineArgs is the
          >recommended way now :)
          \
          Why?
          >
          I meant that it is recommended over the Command function. In the
          documentation, it cliams that the My method is faster and more
          efficeint.
          In my idea is the My class only build to make it easier for old VB6 users.
          That does in my idea not make it the recommended way.
          >
          The overloaded constructor is in my idea the normal way for this.
          The overloaded main is the way I handle it in C#, but if your using the
          application framework in VB.NET, using the Main becomes a little more
          difficult. I personally would use the System.Environm ent properties.

          --
          Tom Shelton

          Comment

          • =?Utf-8?B?U2VyZ2lv?=

            #6
            Re: Application Parameters

            thanks Onur,

            this works great, but always display one message (even if no parameters are
            passed), the path of the .exe file, for ex: "c:\myApp\myApp .exe", any ideas?

            Sergio.

            "kimiraikko nen" wrote:
            On Apr 22, 12:18 am, Sergio <Ser...@discuss ions.microsoft. comwrote:
            I need to pass two parameter to a vb.net 2003 windows form application, is
            this posible? how?
            >
            Sergio,
            You can launch your application with passing parameters using.
            Generally, the parameters are passed when form's load event is fired.
            So you can do;
            >
            You can get all the parameters that are passed on application startup;
            >
            Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
            System.EventArg s) Handles MyBase.Load
            For Each x As String In Environment.Get CommandLineArgs
            MsgBox(x)
            Next
            End Sub
            >
            Hope this helps,
            >
            Onur
            >
            >

            Comment

            • Cor Ligthert[MVP]

              #7
              Re: Application Parameters

              Tom,

              Jay B has once written all the possibilities he knew that there were with
              with Sub Main in VB.Net (I thought that he was showing 12), I thought that
              Armin and Herfried are never creating a real solution without that.

              However as you know, only for the record.

              Cor


              "Tom Shelton" <tom_shelton@YO UKNOWTHEDRILLco mcast.netschree f in bericht
              news:%231lm1AIp IHA.4760@TK2MSF TNGP06.phx.gbl. ..
              On 2008-04-22, Cor Ligthert[MVP] <notmyfirstname @planet.nlwrote :
              >Tom,
              >>
              >>My.Applicatio n.CommandLineAr gs property as well as the old VB Command
              >>function. I believe that the My.Application. CommandLineArgs is the
              >>recommended way now :)
              >\
              >Why?
              >>
              >
              I meant that it is recommended over the Command function. In the
              documentation, it cliams that the My method is faster and more
              efficeint.
              >
              >In my idea is the My class only build to make it easier for old VB6
              >users.
              >That does in my idea not make it the recommended way.
              >>
              >The overloaded constructor is in my idea the normal way for this.
              >
              The overloaded main is the way I handle it in C#, but if your using the
              application framework in VB.NET, using the Main becomes a little more
              difficult. I personally would use the System.Environm ent properties.
              >
              --
              Tom Shelton

              Comment

              • Patrice

                #8
                Re: Application Parameters

                This is usual in most parameters reading API. Also the .NET doc says so :

                (from
                http://msdn2.microsoft.com/en-us/lib...dlineargs.aspx) :

                Return Value
                Type: array< System..::.Stri ng >[]()[]

                An array of string where each element contains a command-line argument. The
                first element is the executable file name, and the following zero or more
                elements contain the remaining command-line arguments.

                --
                Patrice

                "Sergio" <Sergio@discuss ions.microsoft. coma écrit dans le message de
                groupe de discussion : D70169B7-FCFF-4137-A3E2-D5AD5699E870@mi crosoft.com...
                thanks Onur,
                >
                this works great, but always display one message (even if no parameters
                are
                passed), the path of the .exe file, for ex: "c:\myApp\myApp .exe", any
                ideas?
                >
                Sergio.
                >
                "kimiraikko nen" wrote:
                >
                >On Apr 22, 12:18 am, Sergio <Ser...@discuss ions.microsoft. comwrote:
                I need to pass two parameter to a vb.net 2003 windows form application,
                is
                this posible? how?
                >>
                >Sergio,
                >You can launch your application with passing parameters using.
                >Generally, the parameters are passed when form's load event is fired.
                >So you can do;
                >>
                >You can get all the parameters that are passed on application startup;
                >>
                >Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
                >System.EventAr gs) Handles MyBase.Load
                >For Each x As String In Environment.Get CommandLineArgs
                >MsgBox(x)
                >Next
                >End Sub
                >>
                >Hope this helps,
                >>
                >Onur
                >>
                >>

                Comment

                • kimiraikkonen

                  #9
                  Re: Application Parameters

                  On Apr 22, 7:39 pm, Sergio <Ser...@discuss ions.microsoft. comwrote:
                  thanks Onur,
                  >
                  this works great, but always display one message (even if no parameters are
                  passed), the path of the .exe file, for ex: "c:\myApp\myApp .exe", any ideas?
                  >
                  Sergio.
                  >
                  "kimiraikko nen" wrote:
                  On Apr 22, 12:18 am, Sergio <Ser...@discuss ions.microsoft. comwrote:
                  I need to pass two parameter to a vb.net 2003 windows form application, is
                  this posible? how?
                  >
                  Sergio,
                  You can launch your application with passing parameters using.
                  Generally, the parameters are passed when form's load event is fired.
                  So you can do;
                  >
                  You can get all the parameters that are passed on application startup;
                  >
                  Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
                  System.EventArg s) Handles MyBase.Load
                  For Each x As String In Environment.Get CommandLineArgs
                  MsgBox(x)
                  Next
                  End Sub
                  >
                  Hope this helps,
                  >
                  Onur
                  Sergio,
                  Sure, it displays only your application's path if you didn't pass
                  additional parameters. Because first parameter refers to your
                  application's path, the rest are usually custom ones that you pass.

                  If you want to use a specific parameter, you may specify its index in
                  command-line argument array then use where you want(form's load on
                  example above). :-)

                  For example, if you want to get only second parameter which is your
                  custom parameter and its index is 1 ( zero is application's path,
                  remember), you may do;

                  ' Start app like this
                  ' c:\yourapp.exe param1 param2 param3


                  ' To get param1
                  If Environment.Get CommandLineArgs ().Length 1 Then
                  Dim my_params() As String = Environment.Get CommandLineArgs ()
                  MsgBox(my_param s(1))
                  End If

                  Use the same logic for param2, param3... for instance.

                  Hope this helps,

                  Onur Güzel

                  Comment

                  • =?Utf-8?B?U2VyZ2lv?=

                    #10
                    Re: Application Parameters

                    Thanks, finally i used

                    Environment.Get CommandLineArgs .GetValue(1)


                    "kimiraikko nen" wrote:
                    On Apr 22, 7:39 pm, Sergio <Ser...@discuss ions.microsoft. comwrote:
                    thanks Onur,

                    this works great, but always display one message (even if no parameters are
                    passed), the path of the .exe file, for ex: "c:\myApp\myApp .exe", any ideas?

                    Sergio.

                    "kimiraikko nen" wrote:
                    On Apr 22, 12:18 am, Sergio <Ser...@discuss ions.microsoft. comwrote:
                    I need to pass two parameter to a vb.net 2003 windows form application, is
                    this posible? how?
                    Sergio,
                    You can launch your application with passing parameters using.
                    Generally, the parameters are passed when form's load event is fired.
                    So you can do;
                    You can get all the parameters that are passed on application startup;
                    Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
                    System.EventArg s) Handles MyBase.Load
                    For Each x As String In Environment.Get CommandLineArgs
                    MsgBox(x)
                    Next
                    End Sub
                    Hope this helps,
                    Onur
                    >
                    Sergio,
                    Sure, it displays only your application's path if you didn't pass
                    additional parameters. Because first parameter refers to your
                    application's path, the rest are usually custom ones that you pass.
                    >
                    If you want to use a specific parameter, you may specify its index in
                    command-line argument array then use where you want(form's load on
                    example above). :-)
                    >
                    For example, if you want to get only second parameter which is your
                    custom parameter and its index is 1 ( zero is application's path,
                    remember), you may do;
                    >
                    ' Start app like this
                    ' c:\yourapp.exe param1 param2 param3
                    >
                    >
                    ' To get param1
                    If Environment.Get CommandLineArgs ().Length 1 Then
                    Dim my_params() As String = Environment.Get CommandLineArgs ()
                    MsgBox(my_param s(1))
                    End If
                    >
                    Use the same logic for param2, param3... for instance.
                    >
                    Hope this helps,
                    >
                    Onur Güzel
                    >

                    Comment

                    • kimiraikkonen

                      #11
                      Re: Application Parameters

                      On Apr 22, 8:52 pm, Sergio <Ser...@discuss ions.microsoft. comwrote:
                      Thanks, finally i used
                      >
                      Environment.Get CommandLineArgs .GetValue(1)
                      >
                      "kimiraikko nen" wrote:
                      On Apr 22, 7:39 pm, Sergio <Ser...@discuss ions.microsoft. comwrote:
                      thanks Onur,
                      >
                      this works great, but always display one message (even if no parameters are
                      passed), the path of the .exe file, for ex: "c:\myApp\myApp .exe", any ideas?
                      >
                      Sergio.
                      >
                      "kimiraikko nen" wrote:
                      On Apr 22, 12:18 am, Sergio <Ser...@discuss ions.microsoft. comwrote:
                      I need to pass two parameter to a vb.net 2003 windows form application, is
                      this posible? how?
                      >
                      Sergio,
                      You can launch your application with passing parameters using.
                      Generally, the parameters are passed when form's load event is fired..
                      So you can do;
                      >
                      You can get all the parameters that are passed on application startup;
                      >
                      Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
                      System.EventArg s) Handles MyBase.Load
                      For Each x As String In Environment.Get CommandLineArgs
                      MsgBox(x)
                      Next
                      End Sub
                      >
                      Hope this helps,
                      >
                      Onur
                      >
                      Sergio,
                      Sure, it displays only your application's path if you didn't pass
                      additional parameters. Because first parameter refers to your
                      application's path, the rest are usually custom ones that you pass.
                      >
                      If you want to use a specific parameter, you may specify its index in
                      command-line argument array then use where you want(form's load on
                      example above). :-)
                      >
                      For example, if you want to get only second parameter which is your
                      custom parameter and its index is 1 ( zero is application's path,
                      remember), you may do;
                      >
                      ' Start app like this
                      ' c:\yourapp.exe param1 param2 param3
                      >
                      ' To get param1
                      If Environment.Get CommandLineArgs ().Length 1 Then
                      Dim my_params() As String = Environment.Get CommandLineArgs ()
                      MsgBox(my_param s(1))
                      End If
                      >
                      Use the same logic for param2, param3... for instance.
                      >
                      Hope this helps,
                      >
                      Onur Güzel
                      Good alternative :)

                      However don't forget to put if conditional, because there may come up
                      situations that you need to start your app without passing your custom
                      parameter, then you'd better;

                      If Environment.Get CommandLineArgs ().Length 1 Then
                      MsgBox(Environm ent.GetCommandL ineArgs().GetVa lue(1))
                      End If

                      Regards,

                      Onur

                      Comment

                      • Tom Shelton

                        #12
                        Re: Application Parameters

                        On 2008-04-22, Cor Ligthert[MVP] <notmyfirstname @planet.nlwrote :
                        Tom,
                        >
                        Jay B has once written all the possibilities he knew that there were with
                        with Sub Main in VB.Net (I thought that he was showing 12), I thought that
                        Armin and Herfried are never creating a real solution without that.
                        >
                        However as you know, only for the record.
                        >
                        Cor
                        >
                        Without access modifiers, it's something like:

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

                        Armin and Herfried probably don't use the application framework, either
                        :)

                        --
                        Tom Shelton

                        Comment

                        Working...