|
-
Sep 19th, 2002, 03:28 PM
#1
Thread Starter
Junior Member
HELP! reference control by string
is there a way to reference a control (button or checkbox) by using a string for its name instead of an integer?
I want to loop through a recordset with names of controls and add or remove them based on values in the recordset.
I am converting from vba where this worked:
CHKNAME = "chk" & rc![Report]
Set ctl = FRM.Controls(CHKNAME)
thanks
-
Sep 19th, 2002, 11:09 PM
#2
Junior Member
Try
Code:
Dim aryCtl() As Control
aryCtl = GetFormControls(me)
For I = 0 to Ubound(aryCtl)
if aryCtl(I).Name .....
Next
Public Function GetFormControls(frm as Form) As Control()
Dim aryCtl() As Control
Dim intIdx As Integer = -1
ReDim aryCtl(200)
GetFormControls2(frm.Controls, aryCtl, intIdx)
ReDim Preserve aryCtl(intIdx) ' Resize the array
Return aryCtl
End Function
Private Sub GetFormControls2(ByVal ctlControls As Control.ControlCollection, _
ByVal aryCtl As Control(), ByRef intIdx As Integer)
Dim ctlW As Control
Dim intBound As Integer
intBound = aryCtl.GetUpperBound(0)
For Each ctlW In ctlControls
intIdx = intIdx + 1
If intIdx > intBound Then
ReDim Preserve aryCtl(intIdx * 2)
intBound = aryCtl.GetUpperBound(0)
End If
aryCtl(intIdx) = ctlW
If Not (ctlW.Controls Is Nothing) AndAlso ctlW.Controls.Count > 0 Then
GetFormControls2(ctlW.Controls, aryCtl, intIdx)
End If
Next
End Sub
-
Sep 20th, 2002, 10:35 AM
#3
yay gay
correct me if im wrong but u could use the callbyname() function in vb6 namespace
-
Sep 20th, 2002, 12:55 PM
#4
Junior Member
You are mistaken.
CallByname "Executes a method on an object, or sets or returns a property on an object". The name of the method or property is contained in a string, not the name of the control.
Code:
Public Function CallByName( _
ByVal Object As System.Object, _
ByVal ProcName As String, _
ByVal UseCallType As CallType, _
ByVal ParamArrayArgs() As Object _
) As Object
Object
Required. Object. A pointer to the object exposing the property or method.
ProcName
Required. String. A string expression containing the name of the property or method on the object.
-
Sep 20th, 2002, 01:04 PM
#5
Thread Starter
Junior Member
CALLBYNAME WORKS, THANKS
IT WORKS:
Public WithEvents cmd_inorg_clp_11and12 As New Button()
Dim ctl As Object
ctl = CallByName(Me, "cmd_inorg_clp_11and12", CallType.Get)
Dim chkx As Integer
Dim cmdx As Integer
Dim chkandcmdy As Integer
chkx = 30
cmdx = 50
chkandcmdy = 50
With ctl
.Location = New Point(50, 50)
.Text = "INORG CLP 11 AND 12"
.Width = 180
.Height = 20
End With
Me.TabControl1.TabPages.Item(1).Controls.Add(ctl)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|