|
-
May 30th, 2008, 07:47 PM
#1
Thread Starter
Addicted Member
[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
-
May 30th, 2008, 08:30 PM
#2
Re: passing objects on a sub-procedure
Code:
Set objControl = objCtrl
-
May 30th, 2008, 08:34 PM
#3
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
Last edited by RhinoBull; May 30th, 2008 at 08:37 PM.
-
May 30th, 2008, 08:41 PM
#4
Thread Starter
Addicted Member
Re: passing objects on a sub-procedure
arrgh, I forgot about that set stuff.. thanks a lot jcis
-
May 30th, 2008, 08:43 PM
#5
Thread Starter
Addicted Member
Re: passing objects on a sub-procedure
 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?
-
May 30th, 2008, 09:03 PM
#6
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.
-
May 30th, 2008, 09:27 PM
#7
Thread Starter
Addicted Member
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..
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
|