Results 1 to 7 of 7

Thread: [RESOLVED] passing objects on a sub-procedure

  1. #1

    Thread Starter
    Addicted Member leinkyle's Avatar
    Join Date
    Mar 2008
    Location
    Manila
    Posts
    150

    Resolved [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:
    1. Public Sub ControlSet(objCtrl As Object, strButton As String, intIndex As Integer)
    2. objControl = objCtrl  'object variable or  with blocked variable not set (error says)
    3. intControlIndex = intIndex

    and this is the command button where the object,the string, and the index value of the arrayed command button

    vb Code:
    1. Private Sub cmdFields_Click(Index As Integer)
    2. frmAddItems.ControlSet Me.cmdFields, "cmdFields", Index
    3. frmAddItems.Show vbModal
    4. 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
    No matter how hard life is, you still have to learn how to smile..ayt?!


    Sorry still a Newbie

    As a developer, one of your inherent traits is supposed to be your flexibility and adaptability to any new environment.
    "Aargh, not the eyes, oh it burns. It burns!"

    ---mhendak

  2. #2
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: passing objects on a sub-procedure

    Code:
    Set objControl = objCtrl

  3. #3
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    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

  4. #4

    Thread Starter
    Addicted Member leinkyle's Avatar
    Join Date
    Mar 2008
    Location
    Manila
    Posts
    150

    Re: passing objects on a sub-procedure

    arrgh, I forgot about that set stuff.. thanks a lot jcis
    No matter how hard life is, you still have to learn how to smile..ayt?!


    Sorry still a Newbie

    As a developer, one of your inherent traits is supposed to be your flexibility and adaptability to any new environment.
    "Aargh, not the eyes, oh it burns. It burns!"

    ---mhendak

  5. #5

    Thread Starter
    Addicted Member leinkyle's Avatar
    Join Date
    Mar 2008
    Location
    Manila
    Posts
    150

    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?
    No matter how hard life is, you still have to learn how to smile..ayt?!


    Sorry still a Newbie

    As a developer, one of your inherent traits is supposed to be your flexibility and adaptability to any new environment.
    "Aargh, not the eyes, oh it burns. It burns!"

    ---mhendak

  6. #6
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    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.

  7. #7

    Thread Starter
    Addicted Member leinkyle's Avatar
    Join Date
    Mar 2008
    Location
    Manila
    Posts
    150

    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..
    No matter how hard life is, you still have to learn how to smile..ayt?!


    Sorry still a Newbie

    As a developer, one of your inherent traits is supposed to be your flexibility and adaptability to any new environment.
    "Aargh, not the eyes, oh it burns. It burns!"

    ---mhendak

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width