|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
VB2005 Control ArraysHere'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 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. Some good points. I printed it out and will wait to see if other ideas are
forthcoming. Thanks GalenS Show quoteHide quote "creator_bob" <robertbrich***@hotmail.com> wrote in message news:1145464225.969148.104150@i40g2000cwc.googlegroups.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. > 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/default.asp?url=/library/en-us/dnadvnet/ht ml/vbnet05132003.asp "Creating Control Arrays in Visual Basic .NET and Visual C# .NET" http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vstechar t/html/vbtchCreatingControlArraysInVisualBasicNETVisualCNET.asp "Accessing controls by their names or indices" http://dotnet.mvps.org/dotnet/faqs/?id=controlbynameindex&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. ============== 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 Show quoteHide quote news:pYYLqLEZGHA.5300@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/default.asp?url=/library/en-us/dnadvnet/ht > ml/vbnet05132003.asp > "Creating Control Arrays in Visual Basic .NET and Visual C# .NET" > http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vstechar > t/html/vbtchCreatingControlArraysInVisualBasicNETVisualCNET.asp > "Accessing controls by their names or indices" > http://dotnet.mvps.org/dotnet/faqs/?id=controlbynameindex&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. > ============== > 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.
.empty
Rnd() vs. Long ...no joy with LSB! FTP with SSL difference between cstr vs .ToString vs Ctype Visual Studio 2005 Outlook 2000 making 600 dpi A3 size images How to prevent "Input string was not in a correct format" in DataGridView Timeout Copying from Novel Calling Access based Modules from Vb.Net |
|||||||||||||||||||||||