468,119 Members | 2,072 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,119 developers. It's quick & easy.

VB2005 Control Arrays

Just looking for thoughts on converting VB6 Control arrays.

Here's the way I did it. The control happens to be a Usercontrol, CircVol,
but could be any control.

I would appreciate any suggestions on a better way to do it.

GalenS
DECLARATION
Public UserSwp As ArrayList

FORM_LOAD
BuildUserSwp()

BUILD
Private Sub BuildUserSwp()
UserSwp = New ArrayList
UserSwp.Add(CircVol1)
UserSwp.Add(CircVol2)
UserSwp.Add(CircVol3)
UserSwp.Add(CircVol4)
UserSwp.Add(CircVol5)
UserSwp.Add(CircVol6)
End Sub
BUTTON_CLICK
Private Sub UserSwpAll_Click(ByVal sender As Object, ByVal e As
System.EventArgs) _
Handles CircVol1.Click, CircVol2.Click, CircVol3.Click, CircVol4.Click,
_
CircVol5.Click, CircVol6.Click
Dim Index As Integer
Select Case sender.name
Case "CircVol1"
Index = 0
Case "CircVol2"
Index = 1
Case "CircVol3"
Index = 2
Case "CircVol4"
Index = 3
Case "CircVol5"
Index = 4
Case "CircVol6"
Index = 5
End Select
gCtrls.ChnVol(Index) = CByte(UserSwp(Index).volval)
Call UpdatePots(Index, gCtrls.ChnVol(Index))
End Sub

PARTIAL USAGE
For Index = 0 To 4
UserSwp(Index).circName = Chr(Inner)
UserSwp(Index).Width = 90
UserSwp(Index).Height = 97
UserSwp(Index).circBackColor = Me.BackColor
Call SetControl(Index, gCtrls.ChnVol(Index))
LabControl(Index).Text = Chr(Inner)
Inner = Inner + 1
Next
UserSwp(5).Name = "LUNG"
UserSwp(5).circBackColor = Me.BackColor

ANOTHER USAGE
For Index = 1 To 6
gCtrls.ChnVol(Index - 1) = gbytEPA(Index)
frmSweep.UserSwp(Index - 1).VolVal = gbytEPA(Index)
Next Index
Apr 19 '06 #1
5 2156
Rather than the name, I prefer to use the tag property and give it an
integer. If your tag is already used for something else and you want a
design-time array, I would probaby parse my name string instead of
using brute force; maybe write a function that strips all alpha
characters off the senders name and returns only the number.

For run-time created arrays, I can add a handle one at a time.

For X=... to ...
....
Control=new button
Control.Tag=X
' Set location and size
myForm.Controls.Add(Control)
AddHandler Control.Click, AddressOf Button_Click

....
Private Sub Button_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs)
with DirectCast(Sender, Button) ' Avoids late binding. It probably
doesn't hurt speed much, though. I do it for intellisense rather than
speed anyway.
' Use ".tag" to see which button it is.

Apr 19 '06 #2
Some good points. I printed it out and will wait to see if other ideas are
forthcoming.

Thanks
GalenS

"creator_bob" <ro************@hotmail.com> wrote in message
news:11**********************@i40g2000cwc.googlegr oups.com...
Rather than the name, I prefer to use the tag property and give it an
integer. If your tag is already used for something else and you want a
design-time array, I would probaby parse my name string instead of
using brute force; maybe write a function that strips all alpha
characters off the senders name and returns only the number.

For run-time created arrays, I can add a handle one at a time.

For X=... to ...
...
Control=new button
Control.Tag=X
' Set location and size
myForm.Controls.Add(Control)
AddHandler Control.Click, AddressOf Button_Click

...
Private Sub Button_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs)
with DirectCast(Sender, Button) ' Avoids late binding. It probably
doesn't hurt speed much, though. I do it for intellisense rather than
speed anyway.
' Use ".tag" to see which button it is.

Apr 19 '06 #3
Hi Galen,

I think the following articles should be helpful to you:
"Getting Back Your Visual Basic 6.0 Goodies"
http://msdn.microsoft.com/library/de...us/dnadvnet/ht
ml/vbnet05132003.asp
"Creating Control Arrays in Visual Basic .NET and Visual C# .NET"
http://msdn.microsoft.com/library/de...us/dv_vstechar
t/html/vbtchCreatingControlArraysInVisualBasicNETVisualCN ET.asp
"Accessing controls by their names or indices"
http://dotnet.mvps.org/dotnet/faqs/?...eindex&lang=en

Hope this helps!

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
==============

Apr 20 '06 #4
Very interesting but I still like my method better. I will probably modify
per "Creator_bob's" suggestions.

Since I refer to these controls throughout my program I like to use
MyButton(index).Checked instead of stuff like

Dim obj As Object
Dim iCount As Integer = 0
For Each obj In colMyCheckBoxes
If TypeOf obj Is CheckBox Then
Dim chkCheckBox As CheckBox
chkCheckBox = CType(obj, CheckBox)
If chkCheckBox.Checked Then
iCount += 1
End If
End If
Next

GalenS

""Jeffrey Tan[MSFT]"" <je***@online.microsoft.com> wrote in message
news:pY**************@TK2MSFTNGXA01.phx.gbl...
Hi Galen,

I think the following articles should be helpful to you:
"Getting Back Your Visual Basic 6.0 Goodies"
http://msdn.microsoft.com/library/de...us/dnadvnet/ht
ml/vbnet05132003.asp
"Creating Control Arrays in Visual Basic .NET and Visual C# .NET"
http://msdn.microsoft.com/library/de...us/dv_vstechar
t/html/vbtchCreatingControlArraysInVisualBasicNETVisualCN ET.asp
"Accessing controls by their names or indices"
http://dotnet.mvps.org/dotnet/faqs/?...eindex&lang=en

Hope this helps!

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.
==============

Apr 20 '06 #5
Ok, if you need further help, please feel free to post. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Apr 21 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.

By using this site, you agree to our Privacy Policy and Terms of Use.