Upgrade Question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Joseph@aol.com

    #1

    Upgrade Question

    I am rewriting a VB6 program from scratch. In vb6 I had an index
    commandbtton and was able to do use a for loop to make changes to the
    entire group of button. For example the following code worked out ok


    Dim i As Integer
    For i = 0 To cmdButtn.Count - 1
    With cmdButtn(i)
    .ToolTipText = .Caption
    End With
    Next i


    As per every other programmer I am trying not to use the upgrade
    wizard. Is there an easy way to translate this in vb.net
  • Tom Shelton

    #2
    Re: Upgrade Question


    Joseph@aol.com wrote:
    I am rewriting a VB6 program from scratch. In vb6 I had an index
    commandbtton and was able to do use a for loop to make changes to the
    entire group of button. For example the following code worked out ok
    >
    >
    Dim i As Integer
    For i = 0 To cmdButtn.Count - 1
    With cmdButtn(i)
    .ToolTipText = .Caption
    End With
    Next i
    >
    >
    As per every other programmer I am trying not to use the upgrade
    wizard. Is there an easy way to translate this in vb.net
    Here is one possible anser:
    http://msdn.microsoft.com/library/de...visualcnet.asp

    The other is just to stick the buttons in an actuall array or a Generic
    List (if you using 2005) and then you can iterate the list:

    for each btn in buttonList
    btn.text = "hi"
    next

    HTH,

    --
    Tom Shelton

    Comment

    • Branco Medeiros

      #3
      Re: Upgrade Question


      Joseph@aol.com wrote:
      I am rewriting a VB6 program from scratch. In vb6 I had an index
      commandbtton and was able to do use a for loop to make changes to the
      entire group of button. For example the following code worked out ok
      >
      >
      Dim i As Integer
      For i = 0 To cmdButtn.Count - 1
      With cmdButtn(i)
      .ToolTipText = .Caption
      End With
      Next i
      >
      >
      As per every other programmer I am trying not to use the upgrade
      wizard. Is there an easy way to translate this in vb.net
      I don't think you would call this "easy", but you might *manually* put
      the buttons in an array...

      <aircode>
      'at Form scope
      private mButtons() As Button = { _
      cmdButton01, cmdButton02, cmdButton3, ..., cmdButtonN _
      }

      'Somewhere else in code
      For Each B as Button In mButtons
      B.ToolTipText = B.Caption
      Next
      </aircode>

      HTH.

      Regards,

      Branco.

      Comment

      • RobinS

        #4
        Re: Upgrade Question

        Control arrays have gone away. (Bummer, I used them, too.)

        If you want to hit all the buttons on a form, you could do the
        following. This sets the tooltiptext equal to the caption
        on the button. The [caption] property has been replaced
        by the [text] property.

        This is recursive so if you have panels on your form or
        some other kind of container, it checks the controls in
        that container as well.

        Private Sub SetButtonText(B yVal ctrlContainer As Control)
        For Each ctrl As Control In ctrlContainer.C ontrols
        If TypeOf ctrl Is Button Then
        ctrl.ToolTipTex t = ctrl.Text
        End If
        'if control has children, call this function recursively
        If ctrl.HasChildre n Then
        SetButtonText(c trl)
        End If
        Next
        End Sub


        Robin S.
        -------------------
        <Joseph@aol.com wrote in message
        news:s1kbm294cg pm8qesnfiluuch7 ek8kcrfb1@4ax.c om...
        >I am rewriting a VB6 program from scratch. In vb6 I had an index
        commandbtton and was able to do use a for loop to make changes to the
        entire group of button. For example the following code worked out ok
        >
        >
        Dim i As Integer
        For i = 0 To cmdButtn.Count - 1
        With cmdButtn(i)
        .ToolTipText = .Caption
        End With
        Next i
        >
        >
        As per every other programmer I am trying not to use the upgrade
        wizard. Is there an easy way to translate this in vb.net

        Comment

        • Herfried K. Wagner [MVP]

          #5
          Re: Upgrade Question

          <Joseph@aol.com schrieb:
          >I am rewriting a VB6 program from scratch. In vb6 I had an index
          commandbtton and was able to do use a for loop to make changes to the
          entire group of button.
          Accessing controls by their names or indices
          <URL:http://dotnet.mvps.org/dotnet/faqs/?id=controlbyna meindex&lang=en >

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

          Comment

          • Cor Ligthert [MVP]

            #6
            Re: Upgrade Question

            Joseph

            \\\
            dim cmdButtn() as control = {Mybutton1, Mybutton2, MyMoreButton4}
            For i as integer = 0 To cmdButtn.Count - 1
            cmd(i).ToolTipT ext = cmd(i).Text
            Next
            ///

            I hope this helps,

            Cor


            Comment

            • Joseph@aol.com

              #7
              Re: Upgrade Question

              Thanks for the replys. Can some explain why they were dropped?


              On Fri, 24 Nov 2006 06:46:18 +0100, "Cor Ligthert [MVP]"
              <notmyfirstname @planet.nlwrote :
              >Joseph
              >
              >\\\
              >dim cmdButtn() as control = {Mybutton1, Mybutton2, MyMoreButton4}
              >For i as integer = 0 To cmdButtn.Count - 1
              cmd(i).ToolTipT ext = cmd(i).Text
              >Next
              >///
              >
              >I hope this helps,
              >
              >Cor
              >

              Comment

              • Tom Shelton

                #8
                Re: Upgrade Question


                Joseph@aol.com wrote:
                Thanks for the replys. Can some explain why they were dropped?
                >
                I'm not sure anyone knows the answer to that except MS :) But, I will
                say this, that it is one of the few features I miss. There are lots of
                other ways to get around it - but all of them require manual
                intervention because the designer has no support for control arrays.
                Maybe VB.NET 2008?

                --
                Tom Shelton

                Comment

                • Cor Ligthert [MVP]

                  #9
                  Re: Upgrade Question

                  Joseph,

                  As I showed they are not dropped, every control has now its own control
                  collection as the form has too.

                  However the way they could be set in VB6 was in fact a little bit clumsy, it
                  was something special made only for forms.

                  Cor

                  <Joseph@aol.com schreef in bericht
                  news:890em2d3hh flktik2ml7249c1 p38t37rtq@4ax.c om...
                  Thanks for the replys. Can some explain why they were dropped?
                  >
                  >
                  On Fri, 24 Nov 2006 06:46:18 +0100, "Cor Ligthert [MVP]"
                  <notmyfirstname @planet.nlwrote :
                  >
                  >>Joseph
                  >>
                  >>\\\
                  >>dim cmdButtn() as control = {Mybutton1, Mybutton2, MyMoreButton4}
                  >>For i as integer = 0 To cmdButtn.Count - 1
                  > cmd(i).ToolTipT ext = cmd(i).Text
                  >>Next
                  >>///
                  >>
                  >>I hope this helps,
                  >>
                  >>Cor
                  >>
                  >

                  Comment

                  • Herfried K. Wagner [MVP]

                    #10
                    Re: Upgrade Question

                    "Cor Ligthert [MVP]" <notmyfirstname @planet.nlschri eb:
                    As I showed they are not dropped, every control has now its own control
                    collection as the form has too.
                    Well, would it really be a problem to provide support for control arrays in
                    the designer in addition to the features currently provided? I don't think
                    so.
                    However the way they could be set in VB6 was in fact a little bit clumsy,
                    it was something special made only for forms.
                    I don't think it was clumsy, it was simply VB6's way. With some
                    improvements I'd like to see a replacement in .NET too.

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

                    Comment

                    • Tom Shelton

                      #11
                      Re: Upgrade Question


                      Herfried K. Wagner [MVP] wrote:
                      "Cor Ligthert [MVP]" <notmyfirstname @planet.nlschri eb:
                      As I showed they are not dropped, every control has now its own control
                      collection as the form has too.
                      >
                      Well, would it really be a problem to provide support for control arrays in
                      the designer in addition to the features currently provided? I don't think
                      so.
                      >
                      However the way they could be set in VB6 was in fact a little bit clumsy,
                      it was something special made only for forms.
                      >
                      I don't think it was clumsy, it was simply VB6's way. With some
                      improvements I'd like to see a replacement in .NET too.
                      >
                      I fully agree with you Herfied. This was a nice feature of VB.CLASSIC,
                      that I would love to see implemented in .NET.

                      --
                      Tom Shelton

                      Comment

                      • Cor Ligthert [MVP]

                        #12
                        Re: Upgrade Question

                        Tom,

                        You both don't need my opion in this I assume?

                        :-)

                        Cor

                        "Tom Shelton" <tom_shelton@co mcast.netschree f in bericht
                        news:1164411212 .982769.54380@4 5g2000cws.googl egroups.com...
                        >
                        Herfried K. Wagner [MVP] wrote:
                        >"Cor Ligthert [MVP]" <notmyfirstname @planet.nlschri eb:
                        As I showed they are not dropped, every control has now its own control
                        collection as the form has too.
                        >>
                        >Well, would it really be a problem to provide support for control arrays
                        >in
                        >the designer in addition to the features currently provided? I don't
                        >think
                        >so.
                        >>
                        However the way they could be set in VB6 was in fact a little bit
                        clumsy,
                        it was something special made only for forms.
                        >>
                        >I don't think it was clumsy, it was simply VB6's way. With some
                        >improvements I'd like to see a replacement in .NET too.
                        >>
                        >
                        I fully agree with you Herfied. This was a nice feature of VB.CLASSIC,
                        that I would love to see implemented in .NET.
                        >
                        --
                        Tom Shelton
                        >

                        Comment

                        • Tom Shelton

                          #13
                          Re: Upgrade Question


                          Cor Ligthert [MVP] wrote:
                          Tom,
                          >
                          You both don't need my opion in this I assume?
                          >
                          :-)
                          >
                          Cor

                          All opinions are welcome - as long as they are the same as mine :)

                          --
                          Tom Shelton

                          Comment

                          Working...