Home All Groups Group Topic Archive Search About
Author
27 Oct 2006 3:57 PM
jax1148
In vb6 a group of controls ie command buttons could be refered to by
an index number ie cmdWord(4). This was accomplished by using the
index property of the control. Vb.net does not seem to have the index
property for buttons. Is there a way in vb.net to refer to a group of
controls in a way that includes a unique  index number for the
specific control to be used?

Thanks,
Howard Haisten

Author
27 Oct 2006 4:16 PM
Chris
jax1***@yahoo.com wrote:
> In vb6 a group of controls ie command buttons could be refered to by
> an index number ie cmdWord(4). This was accomplished by using the
> index property of the control. Vb.net does not seem to have the index
> property for buttons. Is there a way in vb.net to refer to a group of
> controls in a way that includes a unique  index number for the
> specific control to be used?
>
> Thanks,
> Howard Haisten

You could add all the button controls to an array on form load.

For Each C as Control in Me.Controls
if typeof C is Button then
'Add to Array
end if
End if
Author
27 Oct 2006 4:20 PM
Theo Verweij
This way, you do not know which button has what index in the array.
If you need to know this, you have to do it by hand, ie:

Dim x(1) as button

x(0)=button1
x(2)=button2

then you can use x in the same way as the controlarray in vb6

Chris wrote:
Show quoteHide quote
> jax1***@yahoo.com wrote:
>> In vb6 a group of controls ie command buttons could be refered to by
>> an index number ie cmdWord(4). This was accomplished by using the
>> index property of the control. Vb.net does not seem to have the index
>> property for buttons. Is there a way in vb.net to refer to a group of
>> controls in a way that includes a unique  index number for the
>> specific control to be used?
>> Thanks,
>> Howard Haisten
>
> You could add all the button controls to an array on form load.
>
> For Each C as Control in Me.Controls
> if typeof C is Button then
> 'Add to Array
> end if
> End if
Author
27 Oct 2006 5:20 PM
Cor Ligthert [MVP]
Or a little bit more simple

Dim x() as button = {button1, button2}

Just a little addition the solution is correct in my opinion,

Cor

Show quoteHide quote
"Theo Verweij" <tverw***@xs4all.nl> schreef in bericht
news:uWn7NPe%23GHA.4376@TK2MSFTNGP03.phx.gbl...
> This way, you do not know which button has what index in the array.
> If you need to know this, you have to do it by hand, ie:
>
> Dim x(1) as button
>
> x(0)=button1
> x(2)=button2
>
> then you can use x in the same way as the controlarray in vb6
>
> Chris wrote:
>> jax1***@yahoo.com wrote:
>>> In vb6 a group of controls ie command buttons could be refered to by
>>> an index number ie cmdWord(4). This was accomplished by using the
>>> index property of the control. Vb.net does not seem to have the index
>>> property for buttons. Is there a way in vb.net to refer to a group of
>>> controls in a way that includes a unique  index number for the
>>> specific control to be used?
>>> Thanks,
>>> Howard Haisten
>>
>> You could add all the button controls to an array on form load.
>>
>> For Each C as Control in Me.Controls
>> if typeof C is Button then
>> 'Add to Array
>> end if
>> End if
Author
27 Oct 2006 5:20 PM
Theo Verweij
Smart thinking Cor, I didn't think of this option.

Cor Ligthert [MVP] wrote:
Show quoteHide quote
> Or a little bit more simple
>
> Dim x() as button = {button1, button2}
>
> Just a little addition the solution is correct in my opinion,
>
> Cor
>
> "Theo Verweij" <tverw***@xs4all.nl> schreef in bericht
> news:uWn7NPe%23GHA.4376@TK2MSFTNGP03.phx.gbl...
>> This way, you do not know which button has what index in the array.
>> If you need to know this, you have to do it by hand, ie:
>>
>> Dim x(1) as button
>>
>> x(0)=button1
>> x(2)=button2
>>
>> then you can use x in the same way as the controlarray in vb6
>>
>> Chris wrote:
>>> jax1***@yahoo.com wrote:
>>>> In vb6 a group of controls ie command buttons could be refered to by
>>>> an index number ie cmdWord(4). This was accomplished by using the
>>>> index property of the control. Vb.net does not seem to have the index
>>>> property for buttons. Is there a way in vb.net to refer to a group of
>>>> controls in a way that includes a unique  index number for the
>>>> specific control to be used?
>>>> Thanks,
>>>> Howard Haisten
>>> You could add all the button controls to an array on form load.
>>>
>>> For Each C as Control in Me.Controls
>>> if typeof C is Button then
>>> 'Add to Array
>>> end if
>>> End if
>
>
Author
27 Oct 2006 4:35 PM
Tim Patrick
If you convert a VB6 project that contains control arrays to VB.NET using
the upgrade wizard, it will add code that simulates control arrays using
some VB6-backward-compatibility classes. Look at that code to see how Microsoft
does it. You can also just include the index number in the control name,
and then access controls as Me.Controls("lblInformation" & indexNumber).

-----
Tim Patrick
Start-to-Finish Visual Basic 2005

Show quoteHide quote
> In vb6 a group of controls ie command buttons could be refered to by
> an index number ie cmdWord(4). This was accomplished by using the
> index property of the control. Vb.net does not seem to have the index
> property for buttons. Is there a way in vb.net to refer to a group of
> controls in a way that includes a unique  index number for the
> specific control to be used?
>
> Thanks,
> Howard Haisten
Author
27 Oct 2006 4:47 PM
Theo Verweij
Using Me.Controls("lblInformation" & IndexNumer) can cause a problem
when using obfuscating techniques.

Tim Patrick wrote:
Show quoteHide quote
> If you convert a VB6 project that contains control arrays to VB.NET
> using the upgrade wizard, it will add code that simulates control arrays
> using some VB6-backward-compatibility classes. Look at that code to see
> how Microsoft does it. You can also just include the index number in the
> control name, and then access controls as Me.Controls("lblInformation" &
> indexNumber).
>
> -----
> Tim Patrick
> Start-to-Finish Visual Basic 2005
>
>> In vb6 a group of controls ie command buttons could be refered to by
>> an index number ie cmdWord(4). This was accomplished by using the
>> index property of the control. Vb.net does not seem to have the index
>> property for buttons. Is there a way in vb.net to refer to a group of
>> controls in a way that includes a unique  index number for the
>> specific control to be used?
>>
>> Thanks,
>> Howard Haisten
>
>
Author
27 Oct 2006 5:21 PM
Tim Patrick
That's true. Personally, I have stopped using control array-type code in
my VB.NET applications, choosing to give unique names to each control. I
can bulk up your code a bit, although it is easy to use a common event handler
for all of the related controls. For those situations where it might make
sense to have a lot of controls with related logic, I try to find other means.
For instance, I implemented a simple numeric keypad. My processing needs
were met by using a common Click event, and using the Text (or Tag) property
of the control to complete my processing.

In other cases, I have migrated the independent controls to an owner-draw
list box or grid control, which turned out better anyway.

-----
Tim Patrick
Start-to-Finish Visual Basic 2005

Show quoteHide quote
> Using Me.Controls("lblInformation" & IndexNumer) can cause a problem
> when using obfuscating techniques.
>
> Tim Patrick wrote:
>
>> If you convert a VB6 project that contains control arrays to VB.NET
>> using the upgrade wizard, it will add code that simulates control
>> arrays using some VB6-backward-compatibility classes. Look at that
>> code to see how Microsoft does it. You can also just include the
>> index number in the control name, and then access controls as
>> Me.Controls("lblInformation" & indexNumber).
>>
>> -----
>> Tim Patrick
>> Start-to-Finish Visual Basic 2005
>>> In vb6 a group of controls ie command buttons could be refered to by
>>> an index number ie cmdWord(4). This was accomplished by using the
>>> index property of the control. Vb.net does not seem to have the
>>> index property for buttons. Is there a way in vb.net to refer to a
>>> group of controls in a way that includes a unique  index number for
>>> the specific control to be used?
>>>
>>> Thanks,
>>> Howard Haisten
Author
27 Oct 2006 6:56 PM
Herfried K. Wagner [MVP]
<jax1***@yahoo.com> schrieb:
> In vb6 a group of controls ie command buttons could be refered to by
> an index number ie cmdWord(4). This was accomplished by using the
> index property of the control. Vb.net does not seem to have the index
> property for buttons. Is there a way in vb.net to refer to a group of
> controls in a way that includes a unique  index number for the
> specific control to be used?

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
27 Oct 2006 10:10 PM
jax1148
On Fri, 27 Oct 2006 11:57:49 -0400, jax1***@yahoo.com wrote:

Thank you for your responses. I appreciate your help very much.
Perhaps as I gain more and more knowledge and skill will vb.net I'll
be able to be of assistance to someone else one day. I went with the
suggestion from Cor Lightert. It worked very well !!

Thanks again
Howard Haisten

Show quoteHide quote
>In vb6 a group of controls ie command buttons could be refered to by
>an index number ie cmdWord(4). This was accomplished by using the
>index property of the control. Vb.net does not seem to have the index
>property for buttons. Is there a way in vb.net to refer to a group of
>controls in a way that includes a unique  index number for the
>specific control to be used?
>
>Thanks,
>Howard Haisten