473,387 Members | 1,492 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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...including any third party tools.

Thanks
Nov 14 '06 #1
4 2563
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...including 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(sender 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(sender, TextBox)
end if

select case myTxt.Name.ToLower
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.microsoft.comwrote in message
news:E9**********************************@microsof t.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...including 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 MyTextBoxHandler(ByVal sender As Object, ByVal e As System.EventArgs)
_
Handles TextBox1.TextChanged, TextBox2.TextChanged, TextBox3.TextChanged
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(sender 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(sender, TextBox)
end if
select case myTxt.Name.ToLower
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.microsoft.comwrote in
message news:E9**********************************@microsof t.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...including any third party
tools.

Thanks

Nov 15 '06 #4
Hmm, cool. I didn't even think about chaining the Handles keyword...
"Tim Patrick" <in*****@invalid.com.invalidwrote in message
news:e3*************************@newsgroups.comcas t.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 MyTextBoxHandler(ByVal sender As Object, ByVal e As
System.EventArgs) _
Handles TextBox1.TextChanged, TextBox2.TextChanged,
TextBox3.TextChanged
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(sender 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(sender, TextBox)
end if
select case myTxt.Name.ToLower
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.microsoft.comwrote in
message news:E9**********************************@microsof t.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...including 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
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
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...
3
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...
3
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...
20
by: samean | last post by:
Hello, Could you explain me,In VB6 using control array,and how about VB.net. Thanks
8
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!...
5
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
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...
13
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...

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.