[RESOLVED] passing objects on a sub-procedure
hi guys, I am making this program where I need to pass the name of the control( or the control) to a sub-procedure, the sub procedure is made inside the another form and I am using it to set the visibility etc. on the second form ( i.e. I pressed this command1(0), on the click event i will set first the visible and locked control on the second form before showing the second form)
I am using an active x control arrayed command button, but I'm having a problem doing this. This is the code and the error says
vb Code:
Public Sub ControlSet(objCtrl As Object, strButton As String, intIndex As Integer)
objControl = objCtrl 'object variable or with blocked variable not set (error says)
intControlIndex = intIndex
and this is the command button where the object,the string, and the index value of the arrayed command button
vb Code:
Private Sub cmdFields_Click(Index As Integer)
frmAddItems.ControlSet Me.cmdFields, "cmdFields", Index
frmAddItems.Show vbModal
End Sub
I have seen a statement that passes an object/control on a sub procedure , but I am not sure how to do it in a arrayed active x ( or maybe I am just confused)
can someone give me a hand on this?..
thanks..
kyle
Re: passing objects on a sub-procedure
Code:
Set objControl = objCtrl
Re: passing objects on a sub-procedure
Or you can type to Control (if you only passing controls to that procedure)
Code:
Private Sub Command1_Click(Index As Integer)
Test Command1(Index)
End Sub
Public Sub Test(ctl As Control)
Debug.Print ctl.Name
On Local Error Resume Next
Debug.Print ctl.Index
End Sub
Re: passing objects on a sub-procedure
arrgh, I forgot about that set stuff.. thanks a lot jcis
Re: passing objects on a sub-procedure
Quote:
Originally Posted by RhinoBull
Or you can type to Control (if you only passing controls to that procedure)
Code:
Private Sub Command1_Click(Index As Integer)
Test Command1(Index)
End Sub
Public Sub Test(ctl As Control)
Debug.Print ctl.Name
On Local Error Resume Next
Debug.Print ctl.Index
End Sub
btw, what's the difference between an Object and a Control data type?
Re: passing objects on a sub-procedure
Object is "generic" data type and Control is more specific.
You can pass say recordset or Word/Excel object (or control for that matter) variables to a Object type argument but you can only pass actual control (button, textbox, etc) to a Control type.
Re: passing objects on a sub-procedure
I see, now I know why did you pass the control to the sub procedure together with its index value.
thanks for the info rhino..