Upgrade Question

  • Thread starter Thread starter Joseph
  • Start date Start date
J

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
 
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/d...ngcontrolarraysinvisualbasicnetvisualcnet.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,
 
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.
 
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.
 
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
 
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?
 
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
 
Cor Ligthert said:
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.
 
Herfried said:
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.


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