What's the VB9 equivalent for this code

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Just_a_fan@home.net

    What's the VB9 equivalent for this code

    In VB6, I could easily take the value from a combo box and make a
    command with it, this: baudrate = cboBaud(listind ex).

    With the new dotted stuff in VB9, I can't seem to do that. Here's an
    example of my problem.

    I have a combo box with various baud rates in it. The user selects one
    and I want to use it.

    However, the command to use it is in the format:
    AxMbaxp1.BaudRa te() = MBAXPLib.enumBa ud.B9600

    The ".B9600" could also be just a ".5" which I could get from the
    listindex (selectedindex I think it is now) from the combo box or I
    could use the B9600 from the selecteditem.to string but I cannot figure
    out how to put either on the end of such a dotted format command.

    What I need is

    AxMbaxp1.BaudRa te() = "MBAXPLib.enumB aud." & _
    cboBaud.selecte ditem.tostring

    This means I have to have a Select Case and run the combo box index and
    pick the right command thereby increasing code bloat about 10 times what
    it should be.

    In general, is there any way to build up a command and avoid using the
    Select Case?

    If anyone remembers "REXX", this could easily be done in that language.
    You just make a variable contain 5 and then issue the command with the
    variable at the end. The first part was fixed and the variable was
    appended at the end. In fact, IBM Assembler macro works the same way.
    You can just use a LCLC and build the command up. (Sorry for dredging up
    history but it seems we are losing flexibility and gaining code bloat)

    Mike Morrow
    MMSA00E62537

  • Scott M.

    #2
    Re: What's the VB9 equivalent for this code

    The thing is that in .NET the way code is compiled does not allow you to
    create code from code in this way. You'll need to use a Case statement.


    <Just_a_fan@hom e.netwrote in message
    news:njid64t72i llhldq5j1t2tipn 9kt9t2fgn@4ax.c om...
    In VB6, I could easily take the value from a combo box and make a
    command with it, this: baudrate = cboBaud(listind ex).
    >
    With the new dotted stuff in VB9, I can't seem to do that. Here's an
    example of my problem.
    >
    I have a combo box with various baud rates in it. The user selects one
    and I want to use it.
    >
    However, the command to use it is in the format:
    AxMbaxp1.BaudRa te() = MBAXPLib.enumBa ud.B9600
    >
    The ".B9600" could also be just a ".5" which I could get from the
    listindex (selectedindex I think it is now) from the combo box or I
    could use the B9600 from the selecteditem.to string but I cannot figure
    out how to put either on the end of such a dotted format command.
    >
    What I need is
    >
    AxMbaxp1.BaudRa te() = "MBAXPLib.enumB aud." & _
    cboBaud.selecte ditem.tostring
    >
    This means I have to have a Select Case and run the combo box index and
    pick the right command thereby increasing code bloat about 10 times what
    it should be.
    >
    In general, is there any way to build up a command and avoid using the
    Select Case?
    >
    If anyone remembers "REXX", this could easily be done in that language.
    You just make a variable contain 5 and then issue the command with the
    variable at the end. The first part was fixed and the variable was
    appended at the end. In fact, IBM Assembler macro works the same way.
    You can just use a LCLC and build the command up. (Sorry for dredging up
    history but it seems we are losing flexibility and gaining code bloat)
    >
    Mike Morrow
    MMSA00E62537
    >

    Comment

    • Steve Gerrard

      #3
      Re: What's the VB9 equivalent for this code

      Just_a_fan@home .net wrote:
      In VB6, I could easily take the value from a combo box and make a
      command with it, this: baudrate = cboBaud(listind ex).
      >
      With the new dotted stuff in VB9, I can't seem to do that. Here's an
      example of my problem.
      >
      Depends on what you add to the combo box in the first place. If you just add
      strings, you will have to match them up again with something. But you can add
      objects directly to the combo. Here is a dumb example, where the enum values are
      added, not their "ToString" text. When you get the enum back, you can get the
      display text and the integer value from it.

      Private Enum Test
      Okay = 27
      Great = 35
      Amazing = 42
      End Enum

      Private Sub Form1_Load(ByVa l sender As System.Object, _
      ByVal e As System.EventArg s) Handles MyBase.Load
      ComboBox1.Items .AddRange( _
      New Object() {Test.Okay, Test.Great, Test.Amazing})
      End Sub

      Private Sub ComboBox1_Selec tedIndexChanged (ByVal sender As System.Object, _
      ByVal e As System.EventArg s) Handles ComboBox1.Selec tedIndexChanged

      If ComboBox1.Selec tedItem IsNot Nothing Then
      Dim x As Test = CType(ComboBox1 .SelectedItem, Test)
      MsgBox("That would be " + x.ToString _
      + " (value = " + CInt(x).ToStrin g + ")")
      End If

      End Sub


      Comment

      • Stephany Young

        #4
        Re: What's the VB9 equivalent for this code

        The 'new dotted stuff in VB9', as you put it, is not new at at all. It has
        been around since VB4 (at least).

        The big question is, how is the ComboBox populated. In the abscence of
        further information, I will assume that it is popluated with the strings,
        "4800", "9600", "14400", etc.

        MBAXPLib.enumBa ud.B9600 is nothing more than an alias for the integral value
        9600, therefore, all that is being assigned to AxMbaxp1.BaudRa te is an
        integer. The use of the enum merely gives you a clue as to what values are
        acceptable.

        Also note that you are assigning a value to a property not a function so the
        syntax is AxMbaxp1.BaudRa te = rather than AxMbaxp1.BaudRa te() =.

        If AxMbaxp1.BaudRa te is, in fact, a function then all you are attempting is
        a comparison that will result in a Boolean value.

        So the question now becomes, how do I turn the value from the ComboBox into
        an integer.

        The Items collection for a ComboBox is a collection of Object, so the
        mechanism you need to use is one that will convert an Object to an Integer
        (or Int32).

        The obvious one is Convert.ToInt32 (cboBaud.Select edItem).

        If you are sure that it can never fail then you can simply use:

        AxMbaxp1.BaudRa te = Convert.ToInt32 (cboBaud.Select edItem)

        The are other variations that you could use, such as:

        AxMbaxp1.BaudRa te = Convert.ToInt32 (cboBaud.Items( cboBaud.Selecte dIndex))
        AxMbaxp1.BaudRa te = Integer.Parse(c boBaud.Selected Item.ToString)
        AxMbaxp1.BaudRa te =
        Integer.Parse(c boBaud.Items(cb oBaud.SelectedI ndex).ToString)

        however, in my opinion, these are more convoluted and add no value to the
        task at hand.

        Of course, if you do not have Option Strict On, which I DO NOT recommend nor
        endorse, you can use:

        AxMbaxp1.BaudRa te = cboBaud.Selecte dItem

        and live with the consequences of the compiler selects an inappropriate
        coercion method, which is no different to what you had in you VB6 example.

        baudrate = cboBaud(listind ex)


        <Just_a_fan@hom e.netwrote in message
        news:njid64t72i llhldq5j1t2tipn 9kt9t2fgn@4ax.c om...
        In VB6, I could easily take the value from a combo box and make a
        command with it, this: baudrate = cboBaud(listind ex).
        >
        With the new dotted stuff in VB9, I can't seem to do that. Here's an
        example of my problem.
        >
        I have a combo box with various baud rates in it. The user selects one
        and I want to use it.
        >
        However, the command to use it is in the format:
        AxMbaxp1.BaudRa te() = MBAXPLib.enumBa ud.B9600
        >
        The ".B9600" could also be just a ".5" which I could get from the
        listindex (selectedindex I think it is now) from the combo box or I
        could use the B9600 from the selecteditem.to string but I cannot figure
        out how to put either on the end of such a dotted format command.
        >
        What I need is
        >
        AxMbaxp1.BaudRa te() = "MBAXPLib.enumB aud." & _
        cboBaud.selecte ditem.tostring
        >
        This means I have to have a Select Case and run the combo box index and
        pick the right command thereby increasing code bloat about 10 times what
        it should be.
        >
        In general, is there any way to build up a command and avoid using the
        Select Case?
        >
        If anyone remembers "REXX", this could easily be done in that language.
        You just make a variable contain 5 and then issue the command with the
        variable at the end. The first part was fixed and the variable was
        appended at the end. In fact, IBM Assembler macro works the same way.
        You can just use a LCLC and build the command up. (Sorry for dredging up
        history but it seems we are losing flexibility and gaining code bloat)
        >
        Mike Morrow
        MMSA00E62537
        >

        Comment

        • Lloyd Sheen

          #5
          Re: What's the VB9 equivalent for this code


          <Just_a_fan@hom e.netwrote in message
          news:njid64t72i llhldq5j1t2tipn 9kt9t2fgn@4ax.c om...
          In VB6, I could easily take the value from a combo box and make a
          command with it, this: baudrate = cboBaud(listind ex).
          >
          With the new dotted stuff in VB9, I can't seem to do that. Here's an
          example of my problem.
          >
          I have a combo box with various baud rates in it. The user selects one
          and I want to use it.
          >
          However, the command to use it is in the format:
          AxMbaxp1.BaudRa te() = MBAXPLib.enumBa ud.B9600
          >
          The ".B9600" could also be just a ".5" which I could get from the
          listindex (selectedindex I think it is now) from the combo box or I
          could use the B9600 from the selecteditem.to string but I cannot figure
          out how to put either on the end of such a dotted format command.
          >
          What I need is
          >
          AxMbaxp1.BaudRa te() = "MBAXPLib.enumB aud." & _
          cboBaud.selecte ditem.tostring
          >
          This means I have to have a Select Case and run the combo box index and
          pick the right command thereby increasing code bloat about 10 times what
          it should be.
          >
          In general, is there any way to build up a command and avoid using the
          Select Case?
          >
          If anyone remembers "REXX", this could easily be done in that language.
          You just make a variable contain 5 and then issue the command with the
          variable at the end. The first part was fixed and the variable was
          appended at the end. In fact, IBM Assembler macro works the same way.
          You can just use a LCLC and build the command up. (Sorry for dredging up
          history but it seems we are losing flexibility and gaining code bloat)
          >
          Mike Morrow
          MMSA00E62537
          >
          Each item in the listbox can be an object. So what you can use is an
          array/list of object where the object has a property which will display and
          a property which you will use as the baudrate.

          When an item is selected there is a selecteditem property for the combobox
          which can get whatever info you want.

          This is a pattern used by listboxes/comboboxes. If you create an array of
          your new object you can then use binding to get the items into the items
          collection of the combox. You will use the DisplayMember to tell the
          combobox what to display.

          This while it may seem lots to do is a pattern to learn and will / can be
          used for every instance of a listbox/combobox.

          Hope this helps
          LS

          Comment

          • Cor Ligthert[MVP]

            #6
            Re: What's the VB9 equivalent for this code

            Mike,

            Just a sample to show you how you can do it using a class (in this case the
            datatable) which contains a lot of sub classes which you intance with the
            New keyword.

            I have not made exatly a sample of your problem, but I have included all
            kind of index methods of the DataRow to use the DataColumn, I hope the
            latter scares you not to much.

            For this you need to drag a combobox on a form.

            \\\
            Private Sub Form1_Load(ByVa l sender As System.Object, _
            ByVal e As System.EventArg s) Handles MyBase.Load
            Dim dt As New DataTable
            Dim dc1 As New DataColumn("Rat e")
            dt.Columns.Add( dc1)
            Dim dc2 As New DataColumn("Rat eLong")
            dt.Columns.Add( dc2)
            Dim firstText = 9600
            For i As Integer = 0 To 3
            Dim dr = dt.NewRow
            dr.Item(0) = firstText.ToStr ing
            dr.Item(1) = firstText.ToStr ing & "Long"
            dt.Rows.Add(dr)
            firstText = firstText + firstText
            Next
            ComboBox1.DataS ource = dt
            ComboBox1.Displ ayMember = dc1.ColumnName
            ComboBox1.Value Member = dc2.ColumnName
            End Sub
            ///

            Cor


            <Just_a_fan@hom e.netschreef in bericht
            news:njid64t72i llhldq5j1t2tipn 9kt9t2fgn@4ax.c om...
            In VB6, I could easily take the value from a combo box and make a
            command with it, this: baudrate = cboBaud(listind ex).
            >
            With the new dotted stuff in VB9, I can't seem to do that. Here's an
            example of my problem.
            >
            I have a combo box with various baud rates in it. The user selects one
            and I want to use it.
            >
            However, the command to use it is in the format:
            AxMbaxp1.BaudRa te() = MBAXPLib.enumBa ud.B9600
            >
            The ".B9600" could also be just a ".5" which I could get from the
            listindex (selectedindex I think it is now) from the combo box or I
            could use the B9600 from the selecteditem.to string but I cannot figure
            out how to put either on the end of such a dotted format command.
            >
            What I need is
            >
            AxMbaxp1.BaudRa te() = "MBAXPLib.enumB aud." & _
            cboBaud.selecte ditem.tostring
            >
            This means I have to have a Select Case and run the combo box index and
            pick the right command thereby increasing code bloat about 10 times what
            it should be.
            >
            In general, is there any way to build up a command and avoid using the
            Select Case?
            >
            If anyone remembers "REXX", this could easily be done in that language.
            You just make a variable contain 5 and then issue the command with the
            variable at the end. The first part was fixed and the variable was
            appended at the end. In fact, IBM Assembler macro works the same way.
            You can just use a LCLC and build the command up. (Sorry for dredging up
            history but it seems we are losing flexibility and gaining code bloat)
            >
            Mike Morrow
            MMSA00E62537
            >

            Comment

            • Just_a_fan@home.net

              #7
              Re: Re: What's the VB9 equivalent for this code

              On Sat, 28 Jun 2008 21:10:11 -0400, in
              microsoft.publi c.dotnet.langua ges.vb "Lloyd Sheen" <a@b.cwrote:
              >
              ><Just_a_fan@ho me.netwrote in message
              >news:njid64t72 illhldq5j1t2tip n9kt9t2fgn@4ax. com...
              >In VB6, I could easily take the value from a combo box and make a
              >command with it, this: baudrate = cboBaud(listind ex).
              >>
              >With the new dotted stuff in VB9, I can't seem to do that. Here's an
              >example of my problem.
              >>
              >I have a combo box with various baud rates in it. The user selects one
              >and I want to use it.
              >>
              >However, the command to use it is in the format:
              >AxMbaxp1.BaudR ate() = MBAXPLib.enumBa ud.B9600
              >>
              >The ".B9600" could also be just a ".5" which I could get from the
              >listindex (selectedindex I think it is now) from the combo box or I
              >could use the B9600 from the selecteditem.to string but I cannot figure
              >out how to put either on the end of such a dotted format command.
              >>
              >What I need is
              >>
              >AxMbaxp1.BaudR ate() = "MBAXPLib.enumB aud." & _
              >cboBaud.select editem.tostring
              >>
              >This means I have to have a Select Case and run the combo box index and
              >pick the right command thereby increasing code bloat about 10 times what
              >it should be.
              >>
              >In general, is there any way to build up a command and avoid using the
              >Select Case?
              >>
              >If anyone remembers "REXX", this could easily be done in that language.
              >You just make a variable contain 5 and then issue the command with the
              >variable at the end. The first part was fixed and the variable was
              >appended at the end. In fact, IBM Assembler macro works the same way.
              >You can just use a LCLC and build the command up. (Sorry for dredging up
              >history but it seems we are losing flexibility and gaining code bloat)
              >>
              >Mike Morrow
              >MMSA00E62537
              >>
              >
              >Each item in the listbox can be an object. So what you can use is an
              >array/list of object where the object has a property which will display and
              >a property which you will use as the baudrate.
              >
              >When an item is selected there is a selecteditem property for the combobox
              >which can get whatever info you want.
              >
              >This is a pattern used by listboxes/comboboxes. If you create an array of
              >your new object you can then use binding to get the items into the items
              >collection of the combox. You will use the DisplayMember to tell the
              >combobox what to display.
              >
              >This while it may seem lots to do is a pattern to learn and will / can be
              >used for every instance of a listbox/combobox.
              >
              >Hope this helps
              >LS
              WOW! What an exquisite level of pain this .NET stuff puts on us to do
              what we used to do quite easily!

              Thanks. I will have to chew on this a while. Seems quite complex and
              difficult. It used to be so easy.

              Now I really miss the help I used to be able to get on stuff. That
              makes it hurt even more.

              Mike

              Comment

              • Just_a_fan@home.net

                #8
                Re: Re: What's the VB9 equivalent for this code

                Yeah, see that's the problem. In good ole VB, you could take that 9600
                from the combo box and just use it. Now one has to write a dozen or so
                lines of very complex code, debug it, maintain it, etc.

                Without being able to symbolically create commands and then issue them,
                things get very difficult. It almost seems like the VB developers are
                working to assure that we all have jobs forever maintaining about 12
                times the code we used to have. Just seems that way...

                Code bloat RULES!

                Thanks for the code. I will try to digest it some day. But, by then, I
                could have done it another way much faster, I think. We will see when I
                have time to get into it. Maybe I am just tired and my brain has gone
                offline. This is the 7th day running, after all. Time to stop!

                Mike

                On Sun, 29 Jun 2008 07:54:18 +0200, in
                microsoft.publi c.dotnet.langua ges.vb "Cor Ligthert[MVP]"
                <notmyfirstname @planet.nlwrote :
                >Mike,
                >
                >Just a sample to show you how you can do it using a class (in this case the
                >datatable) which contains a lot of sub classes which you intance with the
                >New keyword.
                >
                >I have not made exatly a sample of your problem, but I have included all
                >kind of index methods of the DataRow to use the DataColumn, I hope the
                >latter scares you not to much.
                >
                >For this you need to drag a combobox on a form.
                >
                >\\\
                >Private Sub Form1_Load(ByVa l sender As System.Object, _
                ByVal e As System.EventArg s) Handles MyBase.Load
                Dim dt As New DataTable
                Dim dc1 As New DataColumn("Rat e")
                dt.Columns.Add( dc1)
                Dim dc2 As New DataColumn("Rat eLong")
                dt.Columns.Add( dc2)
                Dim firstText = 9600
                For i As Integer = 0 To 3
                Dim dr = dt.NewRow
                dr.Item(0) = firstText.ToStr ing
                dr.Item(1) = firstText.ToStr ing & "Long"
                dt.Rows.Add(dr)
                firstText = firstText + firstText
                Next
                ComboBox1.DataS ource = dt
                ComboBox1.Displ ayMember = dc1.ColumnName
                ComboBox1.Value Member = dc2.ColumnName
                >End Sub
                >///
                >
                >Cor
                >
                >
                ><Just_a_fan@ho me.netschreef in bericht
                >news:njid64t72 illhldq5j1t2tip n9kt9t2fgn@4ax. com...
                >In VB6, I could easily take the value from a combo box and make a
                >command with it, this: baudrate = cboBaud(listind ex).
                >>
                >With the new dotted stuff in VB9, I can't seem to do that. Here's an
                >example of my problem.
                >>
                >I have a combo box with various baud rates in it. The user selects one
                >and I want to use it.
                >>
                >However, the command to use it is in the format:
                >AxMbaxp1.BaudR ate() = MBAXPLib.enumBa ud.B9600
                >>
                >The ".B9600" could also be just a ".5" which I could get from the
                >listindex (selectedindex I think it is now) from the combo box or I
                >could use the B9600 from the selecteditem.to string but I cannot figure
                >out how to put either on the end of such a dotted format command.
                >>
                >What I need is
                >>
                >AxMbaxp1.BaudR ate() = "MBAXPLib.enumB aud." & _
                >cboBaud.select editem.tostring
                >>
                >This means I have to have a Select Case and run the combo box index and
                >pick the right command thereby increasing code bloat about 10 times what
                >it should be.
                >>
                >In general, is there any way to build up a command and avoid using the
                >Select Case?
                >>
                >If anyone remembers "REXX", this could easily be done in that language.
                >You just make a variable contain 5 and then issue the command with the
                >variable at the end. The first part was fixed and the variable was
                >appended at the end. In fact, IBM Assembler macro works the same way.
                >You can just use a LCLC and build the command up. (Sorry for dredging up
                >history but it seems we are losing flexibility and gaining code bloat)
                >>
                >Mike Morrow
                >MMSA00E62537
                >>

                Comment

                • Armin Zingler

                  #9
                  Re: Re: What's the VB9 equivalent for this code

                  <Just_a_fan@hom e.netschrieb
                  Yeah, see that's the problem. In good ole VB, you could take that
                  9600 from the combo box and just use it.
                  In good ole VB, you had to maintain an additional array if you want to store
                  objects associated with the items in the combobox because you weren't able
                  to store every type of object in a combo box. Glad that this is simpler now.


                  Armin

                  Comment

                  • Just_a_fan@home.net

                    #10
                    Re: Re: Re: What's the VB9 equivalent for this code

                    In good ole' VB I DID NOT have to save anything extra. I just used the
                    9600 right out of the selected item. I could put it in a command string
                    and go.

                    Now, it takes databases and lots of lines of messy code.

                    I can't see this as simpler but if you think it is, good for you.

                    That's all for me. A HUGE difference of opinion on what is simpler, a
                    single combo box or dozens of lines of code + a combo box with a
                    database that has to be created and attached to it.

                    Mike

                    On Mon, 30 Jun 2008 05:16:48 +0200, in
                    Microsoft.publi c.dotnet.langua ges.vb "Armin Zingler"
                    <az.nospam@free net.dewrote:
                    ><Just_a_fan@ho me.netschrieb
                    >Yeah, see that's the problem. In good ole VB, you could take that
                    >9600 from the combo box and just use it.
                    >
                    >In good ole VB, you had to maintain an additional array if you want to store
                    >objects associated with the items in the combobox because you weren't able
                    >to store every type of object in a combo box. Glad that this is simpler now.
                    >
                    >
                    >Armin

                    Comment

                    • Cor Ligthert[MVP]

                      #11
                      Re: Re: Re: What's the VB9 equivalent for this code

                      Dozens? messy? Show us how you did it in VB, now you are only telling
                      trash?

                      However, I see now what you want,

                      Drag a Combobox on your screen
                      Go to the propertiews fill the Items Collection with your boudrated
                      Add an Event Combobox1 Selected index changed
                      Do in that
                      AxMbaxp1.BaudRa te() = "MBAXPLib.enumB aud." & Combobox1.selec teditem.tostrin g

                      However that is so simple, I think that nobody would believe that there was
                      somebody who would ask this in 2008.

                      Cor

                      Comment

                      • Chris Dunaway

                        #12
                        Re: What's the VB9 equivalent for this code

                        On Jun 29, 11:31 pm, Just_a_...@home .net wrote:
                        In good ole' VB I DID NOT have to save anything extra. I just used the
                        9600 right out of the selected item. I could put it in a command string
                        and go.
                        >
                        What's stopping you? How is the following code not simple?

                        Private Sub Form1_Load(ByVa l sender As Object, ByVal e As
                        System.EventArg s) Handles MyBase.Load
                        ComboBox1.DataS ource =
                        System.Enum.Get Values(GetType( MBAXPLib.enumBa ud))
                        End Sub

                        Private Sub ComboBox1_Selec tedIndexChanged (ByVal sender As Object,
                        ByVal e As System.EventArg s) Handles ComboBox1.Selec tedIndexChanged
                        AxMbaxp1.BaudRa te = ComboBox1.Selec tedItem
                        End Sub

                        One line of code to set up all the values in the ComboBox and one line
                        to get the value out when selected. How is the VB6 solution more
                        simple than that?

                        Chris

                        Comment

                        • Scott M.

                          #13
                          Re: Re: What's the VB9 equivalent for this code

                          Your reaction is not uncommon for folks that are just coming to VB .NET from
                          VB 6.0.

                          What you begin to realize though, after a short time, is that while some
                          things involved less code in VB 6.0, the qualtiy of that code was garbage.
                          It wasn't OO and it wasn't type-safe. It was full of late-binding calls that
                          degrade performance and open your app up to runtime errors.

                          Once you realize how VB .NET coding is meant to be different than VB 6.0,
                          you begin to appreciate the much more bullet proof, scalable, and better
                          performing code you get in the end.

                          -Scott

                          <Just_a_fan@hom e.netwrote in message
                          news:prdg64tc7i km4q4aoumeh79ik qvum3100n@4ax.c om...
                          Yeah, see that's the problem. In good ole VB, you could take that 9600
                          from the combo box and just use it. Now one has to write a dozen or so
                          lines of very complex code, debug it, maintain it, etc.
                          >
                          Without being able to symbolically create commands and then issue them,
                          things get very difficult. It almost seems like the VB developers are
                          working to assure that we all have jobs forever maintaining about 12
                          times the code we used to have. Just seems that way...
                          >
                          Code bloat RULES!
                          >
                          Thanks for the code. I will try to digest it some day. But, by then, I
                          could have done it another way much faster, I think. We will see when I
                          have time to get into it. Maybe I am just tired and my brain has gone
                          offline. This is the 7th day running, after all. Time to stop!
                          >
                          Mike
                          >
                          On Sun, 29 Jun 2008 07:54:18 +0200, in
                          microsoft.publi c.dotnet.langua ges.vb "Cor Ligthert[MVP]"
                          <notmyfirstname @planet.nlwrote :
                          >
                          >>Mike,
                          >>
                          >>Just a sample to show you how you can do it using a class (in this case
                          >>the
                          >>datatable) which contains a lot of sub classes which you intance with the
                          >>New keyword.
                          >>
                          >>I have not made exatly a sample of your problem, but I have included all
                          >>kind of index methods of the DataRow to use the DataColumn, I hope the
                          >>latter scares you not to much.
                          >>
                          >>For this you need to drag a combobox on a form.
                          >>
                          >>\\\
                          >>Private Sub Form1_Load(ByVa l sender As System.Object, _
                          > ByVal e As System.EventArg s) Handles
                          >MyBase.Load
                          > Dim dt As New DataTable
                          > Dim dc1 As New DataColumn("Rat e")
                          > dt.Columns.Add( dc1)
                          > Dim dc2 As New DataColumn("Rat eLong")
                          > dt.Columns.Add( dc2)
                          > Dim firstText = 9600
                          > For i As Integer = 0 To 3
                          > Dim dr = dt.NewRow
                          > dr.Item(0) = firstText.ToStr ing
                          > dr.Item(1) = firstText.ToStr ing & "Long"
                          > dt.Rows.Add(dr)
                          > firstText = firstText + firstText
                          > Next
                          > ComboBox1.DataS ource = dt
                          > ComboBox1.Displ ayMember = dc1.ColumnName
                          > ComboBox1.Value Member = dc2.ColumnName
                          >>End Sub
                          >>///
                          >>
                          >>Cor
                          >>
                          >>
                          >><Just_a_fan@h ome.netschreef in bericht
                          >>news:njid64t7 2illhldq5j1t2ti pn9kt9t2fgn@4ax .com...
                          >>In VB6, I could easily take the value from a combo box and make a
                          >>command with it, this: baudrate = cboBaud(listind ex).
                          >>>
                          >>With the new dotted stuff in VB9, I can't seem to do that. Here's an
                          >>example of my problem.
                          >>>
                          >>I have a combo box with various baud rates in it. The user selects one
                          >>and I want to use it.
                          >>>
                          >>However, the command to use it is in the format:
                          >>AxMbaxp1.Baud Rate() = MBAXPLib.enumBa ud.B9600
                          >>>
                          >>The ".B9600" could also be just a ".5" which I could get from the
                          >>listindex (selectedindex I think it is now) from the combo box or I
                          >>could use the B9600 from the selecteditem.to string but I cannot figure
                          >>out how to put either on the end of such a dotted format command.
                          >>>
                          >>What I need is
                          >>>
                          >>AxMbaxp1.Baud Rate() = "MBAXPLib.enumB aud." & _
                          >>cboBaud.selec teditem.tostrin g
                          >>>
                          >>This means I have to have a Select Case and run the combo box index and
                          >>pick the right command thereby increasing code bloat about 10 times what
                          >>it should be.
                          >>>
                          >>In general, is there any way to build up a command and avoid using the
                          >>Select Case?
                          >>>
                          >>If anyone remembers "REXX", this could easily be done in that language.
                          >>You just make a variable contain 5 and then issue the command with the
                          >>variable at the end. The first part was fixed and the variable was
                          >>appended at the end. In fact, IBM Assembler macro works the same way.
                          >>You can just use a LCLC and build the command up. (Sorry for dredging up
                          >>history but it seems we are losing flexibility and gaining code bloat)
                          >>>
                          >>Mike Morrow
                          >>MMSA00E6253 7
                          >>>
                          >

                          Comment

                          • Scott M.

                            #14
                            Re: Re: Re: What's the VB9 equivalent for this code

                            Who said .NET programming was "simpler" than VB 6.0?


                            <Just_a_fan@hom e.netwrote in message
                            news:d8og64pv2k 0nujlelmpp3rei8 8b5aa0apf@4ax.c om...
                            In good ole' VB I DID NOT have to save anything extra. I just used the
                            9600 right out of the selected item. I could put it in a command string
                            and go.
                            >
                            Now, it takes databases and lots of lines of messy code.
                            >
                            I can't see this as simpler but if you think it is, good for you.
                            >
                            That's all for me. A HUGE difference of opinion on what is simpler, a
                            single combo box or dozens of lines of code + a combo box with a
                            database that has to be created and attached to it.
                            >
                            Mike
                            >
                            On Mon, 30 Jun 2008 05:16:48 +0200, in
                            Microsoft.publi c.dotnet.langua ges.vb "Armin Zingler"
                            <az.nospam@free net.dewrote:
                            >
                            >><Just_a_fan@h ome.netschrieb
                            >>Yeah, see that's the problem. In good ole VB, you could take that
                            >>9600 from the combo box and just use it.
                            >>
                            >>In good ole VB, you had to maintain an additional array if you want to
                            >>store
                            >>objects associated with the items in the combobox because you weren't able
                            >>to store every type of object in a combo box. Glad that this is simpler
                            >>now.
                            >>
                            >>
                            >>Armin
                            >

                            Comment

                            • J.B. Moreno

                              #15
                              Re: What's the VB9 equivalent for this code

                              <Just_a_fan@hom e.netwrote:
                              In VB6, I could easily take the value from a combo box and make a
                              command with it, this: baudrate = cboBaud(listind ex).
                              That's not making a command, that's using the listindex to get the
                              value of a particular item in a combo box.
                              With the new dotted stuff in VB9, I can't seem to do that. Here's an
                              example of my problem.
                              >
                              I have a combo box with various baud rates in it. The user selects one
                              and I want to use it.
                              >
                              However, the command to use it is in the format:
                              AxMbaxp1.BaudRa te() = MBAXPLib.enumBa ud.B9600
                              >
                              The ".B9600" could also be just a ".5" which I could get from the
                              listindex (selectedindex I think it is now) from the combo box or I
                              could use the B9600 from the selecteditem.to string but I cannot figure
                              out how to put either on the end of such a dotted format command.
                              >
                              What I need is
                              >
                              AxMbaxp1.BaudRa te() = "MBAXPLib.enumB aud." & _
                              cboBaud.selecte ditem.tostring
                              No, you don't -- it's actually possible to do something like that (NOT
                              in a couple of lines of code), but that's not what you want to do.

                              I can't give you the exact code, because I couldn't find anything about
                              the type MBAXPLIB (only reference I could find to it was your own
                              post).

                              You want something like:

                              AxMbaxp1.BaudRa te = integer.parse(c boBaud.Selected Item.ToString() )


                              (Although I suspect this is some code converted by the wizard, and
                              cboBaud isn't actually a combo box at all, in which case the above will
                              need to be changed so that it does refer to the combobox).


                              Post the code that fills the combo box, and a bit about the variable
                              AxMbaxp1 and it's BaudRate property and maybe someone could give you a
                              precise answer.
                              This means I have to have a Select Case and run the combo box index and
                              pick the right command thereby increasing code bloat about 10 times what
                              it should be.
                              When comparing VB6 to VB.NET code bloat is generally a consequences of
                              not knowing how to take the differences between the two into account
                              when writing your code.
                              In general, is there any way to build up a command and avoid using the
                              Select Case?
                              Like I said, yes, but even so that's not what you want to do.

                              Even in a language that would let you do that easily, you wouldn't want
                              to do that -- there's almost always a penalty for going from executing
                              the code to executing a piece of data.
                              If anyone remembers "REXX", this could easily be done in that language.
                              You just make a variable contain 5 and then issue the command with the
                              variable at the end. The first part was fixed and the variable was
                              appended at the end. In fact, IBM Assembler macro works the same way.
                              You can just use a LCLC and build the command up. (Sorry for dredging up
                              history but it seems we are losing flexibility and gaining code bloat)
                              This can be done in a lot of current languages, perl, php, ruby to name
                              just 3. But like I said, you wouldn't want to do it in them either.

                              --
                              J.B. Moreno

                              Comment

                              Working...