Home All Groups Group Topic Archive Search About
Author
23 Nov 2006 4:54 PM
Joseph
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

Author
23 Nov 2006 5:10 PM
Tom Shelton
Jos***@aol.com wrote:
Show quoteHide quote
> 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/default.asp?url=/library/en-us/dv_vstechart/html/vbtchcreatingcontrolarraysinvisualbasicnetvisualcnet.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
Author
23 Nov 2006 5:13 PM
Branco Medeiros
Jos***@aol.com wrote:
Show quoteHide quote
> 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.
Author
23 Nov 2006 6:41 PM
RobinS
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(ByVal ctrlContainer As Control)
    For Each ctrl As Control In ctrlContainer.Controls
        If TypeOf ctrl Is Button Then
            ctrl.ToolTipText = ctrl.Text
        End If
        'if control has children, call this function recursively
        If ctrl.HasChildren Then
            SetButtonText(ctrl)
        End If
    Next
End Sub


Robin S.
-------------------
<Jos***@aol.com> wrote in message
Show quoteHide quote
news:s1kbm294cgpm8qesnfiluuch7ek8kcrfb1@4ax.com...
>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
Author
23 Nov 2006 11:01 PM
Herfried K. Wagner [MVP]
<Jos***@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=controlbynameindex&lang=en>

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://dotnet.mvps.org/dotnet/faqs/>
Author
24 Nov 2006 5:46 AM
Cor Ligthert [MVP]
Joseph

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

I hope this helps,

Cor
Author
24 Nov 2006 2:27 PM
Joseph
Thanks for the replys.  Can some explain why they were dropped?


On Fri, 24 Nov 2006 06:46:18 +0100, "Cor Ligthert [MVP]"
<notmyfirstn***@planet.nl> wrote:

Show quoteHide quote
>Joseph
>
>\\\
>dim cmdButtn() as control = {Mybutton1, Mybutton2, MyMoreButton4}
>For i as integer  = 0 To cmdButtn.Count - 1
>            cmd(i).ToolTipText = cmd(i).Text
>Next
>///
>
>I hope this helps,
>
>Cor
>
Author
24 Nov 2006 5:20 PM
Tom Shelton
Jos***@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
Author
24 Nov 2006 5:29 PM
Cor Ligthert [MVP]
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

<Jos***@aol.com> schreef in bericht
Show quoteHide quote
news:890em2d3hhflktik2ml7249c1p38t37rtq@4ax.com...
> Thanks for the replys.  Can some explain why they were dropped?
>
>
> On Fri, 24 Nov 2006 06:46:18 +0100, "Cor Ligthert [MVP]"
> <notmyfirstn***@planet.nl> wrote:
>
>>Joseph
>>
>>\\\
>>dim cmdButtn() as control = {Mybutton1, Mybutton2, MyMoreButton4}
>>For i as integer  = 0 To cmdButtn.Count - 1
>>            cmd(i).ToolTipText = cmd(i).Text
>>Next
>>///
>>
>>I hope this helps,
>>
>>Cor
>>
>
Author
24 Nov 2006 11:26 PM
Herfried K. Wagner [MVP]
"Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> schrieb:
> 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/>
Author
24 Nov 2006 11:33 PM
Tom Shelton
Herfried K. Wagner [MVP] wrote:
Show quoteHide quote
> "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> schrieb:
> > 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
Author
25 Nov 2006 9:21 AM
Cor Ligthert [MVP]
Tom,

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

:-)

Cor

Show quoteHide quote
"Tom Shelton" <tom_shel***@comcast.net> schreef in bericht
news:1164411212.982769.54380@45g2000cws.googlegroups.com...
>
> Herfried K. Wagner [MVP] wrote:
>> "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> schrieb:
>> > 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
>
Author
25 Nov 2006 9:46 AM
Tom Shelton
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