473,320 Members | 2,080 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,320 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 2549
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.