UserControl reference in a class or .bas module 
Author Message
 UserControl reference in a class or .bas module

Hi all

I have built a user control which manipulates data between two grids.  What
I want to do is to remove some of the code from the control's code module
and place it in either a class module or a standard .bas module. However,
the problem I am running into is I can't seem to pass a reference for the
control to the module so I can use the individual objects on the control.

 For example lets call the user control GRIDS. On GRIDS I have several
command buttons. I wnat to hide 2 of the command buttons So I would code it:

Public Sub Hide_Buttons ()

    cmd1.visible=FALSE
    cmd2.visible=FALSE

End Sub

But I don't want this code in GRIDS code module.  I want to put this is a
.bas Names Buttons.  So can I pass the GRIDS control to this procedure in
Buttons.bas? If so how? Because if I do it as such:

Public Sub Hide_Buttons (control as ctl)

    cmd1.visible=FALSE
    cmd2.visible=FALSE

End Sub

Hide_Buttons GRIDS

I get a run-time error saying the variable is undefined and it highlights
GRIDS.

So what am I doing wrong? Or can't I pass a reference for a user control?

I appreciate any and all opinions and advice.  Thank-you in advance

Paul Stoner



Mon, 04 Nov 2002 03:00:00 GMT  
 UserControl reference in a class or .bas module
Hi Paul:

Quote:
> the problem I am running into is I can't seem to pass a reference for the
> control to the module so I can use the individual objects on the control.

You will have to pass the "Me" object reference, and expose any properties
or methods that you want to use, i.e.

'UserControl
Public Property ScaleLeft() As Single
   ScaleLeft = UserControl.ScaleLeft
End Property

'elsewhere in usercontrol code
modTest.DoThis Me

'modTest
Public Sub DoThis(obj As Object)
   Debug.Print obj.ScaleLeft
End Sub

Hope this helps,

--
Doug Marquardt
(Visual Basic MVP)
http://support.microsoft.com/support/mvp/



Mon, 04 Nov 2002 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Q: Code Module vs UserControl (Form, Class) module.

2. Q: Code Module vs UserControl (Form, Class) module.

3. Q: Code Module vs UserControl (Form, Class) module.

4. UserControl as parameter to a function defined in a Module (BAS) file

5. Circular Reference Between Modules when 2 Class Modules Listen to Each others Events

6. Circular Reference Between Modules when 2 Class Modules Listen to Each others Events

7. class vs bas module

8. ActiveX control, bas/class module mystery

9. Referencing a UserControl inside a Module

10. Visual Basic Activex Interaction Usercontrol / Class Module

11. Access constituent controls of a UserControl from a Class module

12. Reference usercontrol from a class

 

 
Powered by phpBB® Forum Software