473,545 Members | 2,005 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Control Arrays

I'm a recent convert to VB.net from VB6...and I can't believe they don't
support control arrays. I have an app that uses a ton of Control
Arrays...mostly labels and text boxes.

I need some guidance on how to proceed...inclu ding any third party tools.

Thanks
Nov 14 '06 #1
4 2594
Try converting your VB6 application to .NET using the Upgrade Wizard built
in to Visual Studio. To use the wizard, just open your VB6 .vbp file with
the "File/Open Project" command in Visual Studio for .NET. Then check the
code in those forms that use control arrays. The wizard uses some custom
classes that try to simulate access in a control-array-like fashion.

If your control arrays exist to support controls that share all logic in
common, you can now share event handlers among multiple controls. This lets
you give unique names to each control, but still use a common event handler.
If the controls in your control array have completely unrelated logic, it
is best to make them distinct controls with unique names, and dispense with
the control array altogether.

-----
Tim Patrick
Start-to-Finish Visual Basic 2005
I'm a recent convert to VB.net from VB6...and I can't believe they
don't support control arrays. I have an app that uses a ton of
Control Arrays...mostly labels and text boxes.

I need some guidance on how to proceed...inclu ding any third party
tools.

Thanks

Nov 14 '06 #2
Arne,
I use Tim's approach a lot and it works well. So, you can give your controls
unique names and in code use the AddHandler method to set the method for
whatever event it is you are trying to handle. So, you would write a
function, say TextBox_Click(s ender as Object, e as EventArgs)
Then, use the AddHandler method:
AddHandler mytextbox.Click , AddressOf TextBox_Click

Then, in your TextBox_Click routine, you could cast the sender object to a
textbox object and check its name.
So:
Dim myTxt as TextBox
if Typeof sender is TextBox then
myTxt = DirectCast(send er, TextBox)
end if

select case myTxt.Name.ToLo wer
case "myname"
' do something
case else
' do something else
end select

I wasn't looking at the docs when I wrote this so forgive if I've messed up
an parameters to functions

:)
Steve

"Arne Beruldsen" <Ar***********@ discussions.mic rosoft.comwrote in message
news:E9******** *************** ***********@mic rosoft.com...
I'm a recent convert to VB.net from VB6...and I can't believe they don't
support control arrays. I have an app that uses a ton of Control
Arrays...mostly labels and text boxes.

I need some guidance on how to proceed...inclu ding any third party tools.

Thanks

Nov 15 '06 #3
Using the name works fine, but you can also test the object itself using
the "Is" keyword to see if it is actually one of your controls.

Public Sub MyTextBoxHandle r(ByVal sender As Object, ByVal e As System.EventArg s)
_
Handles TextBox1.TextCh anged, TextBox2.TextCh anged, TextBox3.TextCh anged
If (sender Is TextBox1) Then
' ----- Do text box #1 stuff.
ElseIf (sender Is TextBox2) Then
' ----- Do text box #2 stuff.
ElseIf (sender Is TextBox3) Then
' ----- Do text box #3 stuff.
End If

' ----- Then add common code here.

End Sub

Even though, I think it is generally best to handle each control separately,
and call common routines where there are overlaps.

-----
Tim Patrick
Start-to-Finish Visual Basic 2005
Arne,
I use Tim's approach a lot and it works well. So, you can give your
controls
unique names and in code use the AddHandler method to set the method
for
whatever event it is you are trying to handle. So, you would write a
function, say TextBox_Click(s ender as Object, e as EventArgs)
Then, use the AddHandler method:
AddHandler mytextbox.Click , AddressOf TextBox_Click
Then, in your TextBox_Click routine, you could cast the sender object
to a
textbox object and check its name.
So:
Dim myTxt as TextBox
if Typeof sender is TextBox then
myTxt = DirectCast(send er, TextBox)
end if
select case myTxt.Name.ToLo wer
case "myname"
' do something
case else
' do something else
end select
I wasn't looking at the docs when I wrote this so forgive if I've
messed up an parameters to functions

:)
Steve
"Arne Beruldsen" <Ar***********@ discussions.mic rosoft.comwrote in
message news:E9******** *************** ***********@mic rosoft.com...
>I'm a recent convert to VB.net from VB6...and I can't believe they
don't support control arrays. I have an app that uses a ton of
Control Arrays...mostly labels and text boxes.

I need some guidance on how to proceed...inclu ding any third party
tools.

Thanks

Nov 15 '06 #4
Hmm, cool. I didn't even think about chaining the Handles keyword...
"Tim Patrick" <in*****@invali d.com.invalidwr ote in message
news:e3******** *************** **@newsgroups.c omcast.net...
Using the name works fine, but you can also test the object itself using
the "Is" keyword to see if it is actually one of your controls.

Public Sub MyTextBoxHandle r(ByVal sender As Object, ByVal e As
System.EventArg s) _
Handles TextBox1.TextCh anged, TextBox2.TextCh anged,
TextBox3.TextCh anged
If (sender Is TextBox1) Then
' ----- Do text box #1 stuff.
ElseIf (sender Is TextBox2) Then
' ----- Do text box #2 stuff.
ElseIf (sender Is TextBox3) Then
' ----- Do text box #3 stuff.
End If

' ----- Then add common code here.

End Sub

Even though, I think it is generally best to handle each control
separately, and call common routines where there are overlaps.

-----
Tim Patrick
Start-to-Finish Visual Basic 2005
>Arne,
I use Tim's approach a lot and it works well. So, you can give your
controls
unique names and in code use the AddHandler method to set the method
for
whatever event it is you are trying to handle. So, you would write a
function, say TextBox_Click(s ender as Object, e as EventArgs)
Then, use the AddHandler method:
AddHandler mytextbox.Click , AddressOf TextBox_Click
Then, in your TextBox_Click routine, you could cast the sender object
to a
textbox object and check its name.
So:
Dim myTxt as TextBox
if Typeof sender is TextBox then
myTxt = DirectCast(send er, TextBox)
end if
select case myTxt.Name.ToLo wer
case "myname"
' do something
case else
' do something else
end select
I wasn't looking at the docs when I wrote this so forgive if I've
messed up an parameters to functions

:)
Steve
"Arne Beruldsen" <Ar***********@ discussions.mic rosoft.comwrote in
message news:E9******** *************** ***********@mic rosoft.com...
>>I'm a recent convert to VB.net from VB6...and I can't believe they
don't support control arrays. I have an app that uses a ton of
Control Arrays...mostly labels and text boxes.

I need some guidance on how to proceed...inclu ding any third party
tools.

Thanks


Nov 15 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
18595
by: RBohannon | last post by:
Is it possible to create a control array on an unbound form? I would like to be able to loop through a series of unbound text boxes. Thanks.
2
1337
by: Merlin | last post by:
Hi I have a control that allows embeddable editors, so for example I can set a property of controlsEmbeddableEditor =me.TextBox1 on my form, no problem here - what I want to do is the same thing but from a string variable. i.e. I have 14 controls that have a name which is a permutation of 4 characters, my program selects which control to...
3
3841
by: B-Dog | last post by:
I'm capturing the checked radio button to XML file using the name of the radio button. I want to read my xml file to find which button was checked on close and the check the appropriate button when for loads. How do I use a variable control name. This is what I'm trying to do below but of course it doesn't work, I'm rookie. Thanks ...
3
1381
by: Robert | last post by:
How can I declare in VB .NET an array of labels for example and afterwards using a FOR structure load every component of the array? I've used this code but it doesn't work: dim x(10) as label for i=0 to 10 x(i)=new label
20
2370
by: samean | last post by:
Hello, Could you explain me,In VB6 using control array,and how about VB.net. Thanks
8
2307
by: Greg | last post by:
In VB6 I made heavy use of control arrays I see they have been 'deprecated' in vb.Net, with a questionable explanation that they are no longer necessary which just addresses the event issue! Problem is I commonly associated several other controls with the same index inside the event handler - eg a Directory listbox, Label, Checkbox, Textbox...
5
324
by: Brian Shafer | last post by:
Hi, I loved being about to use control arrays in vb classic. Doesn't look like i can do this in vb.net? Any input?
9
5498
by: Michael D. Ober | last post by:
In VB 6, you can create control arrays for your option groups and scan with the following code dim opt as OptionButton for each opt in OptionGroup ' Do something next opt I know VB 2005 doesn't have control arrays, so my question is how do I do the equivalent in VB 2005?
13
1671
by: Just_a_fan | last post by:
I am adding a bunch of controls with the code below. Problem 1: When program flow passes to "UpperChanged" when I click it, the control name is undefined. When I enter: If udUpperLim1.Value 1 Then I get an error that udUpperLim1 is "Not Defined" so I cannot get the value in the control.
0
7669
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7926
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7439
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7773
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5987
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5343
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3468
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3450
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1901
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.