Active x control Question.

How do I make a Command button from a form do something in the User Control?
Like call a sub routine that draws something on the user control.
I don't want the button to be on the User Control I want a button from the Form to do it.

I have written this code in VB 6.0

Form 1

command 1_Click
Call DrawAxes
end sub


UserControl1
Public Function DrawAxes()
Line (100, 3400)-(5000, 3400)
Line (700, 4000)-(700, 700)
End Function

When I run it it says Sub or Function not defined.
It is referenced in the Project components already.  
jlverryAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
wormboy__6Connect With a Mentor Commented:
On the form write this code:

Private Sub Command1_Click()
Dim I as UserControl ' this is the controls original name
I.DrawAxes
end Sub

This will call upon the Drawaxes function in the usercontrol
0
 
jlverryAuthor Commented:
When I do that it gives an error that says "Object variable or With block variable not set."
0
 
VbmasterCommented:
How about

Call UserControl1.DrawAxes

0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
wormboy__6Commented:
What about:

Private Sub Command1_Click()
Dim I as UserControl ' this is the controls original name
Set I = New Usercontrol
I.DrawAxes
End Sub

0
 
VbmasterCommented:
The difference between the code

(1) Call UserControl1.DrawAxes

and

(2) Dim I as UserControl ' this is the controls original name
     Set I = New Usercontrol
     I.DrawAxes

is that code (1) will run the sub in the UserControl1 control, the one you have on the form created in design-time. Code (2) will create a new UserControl control and call the sub in that control.. that means it won't interact with the control you created in design-time.


0
 
jlverryAuthor Commented:
Well I finally got it to work and figured out what I was doing wrong.  This is what worked:

Form1

Private Sub Command1_Click()
Dim I As UserControl
Call UserControl1.drawAxes
End Sub

UserControl1

Public Sub DrawAxes()
Line (100, 3400)-(5000, 3400)
Line (700, 4000)-(700, 700)
End Sub


So it looks like you have to add a 1 to the name of the UserControl1 when you call it.(Unless this is some strange phenom going on with just my computer)  I tried both of your suggestions wormboy 6 but I got errors both times.  Maybe I am still doing something wrong with that method.  Anyway it looks to me like you both contributed to the final answer(wormboy 6 had the Dim I as usercontrol,and Vbmaster had the Call usercontrol1) so I thought I would give you both 50 points. I will accept wormboy 6's answer and then post a "points for Vbmaster only question for you Vbmaster.  Thanks to both of you.
jlverry
0
 
VbmasterCommented:
Humm.. don't know why you added wormboy's "Dim I As UserControl" to the code line I submitted??

You can remove that line because it's of no use for you. What it does is that it creates a new local variable that is of type usercontrol, but you don't use the variable so why create it?
0
 
jlverryAuthor Commented:
I fI leave the Dim I as userControl out I get an error message.  The only way I can get it to work is to include both lines.  Unless I am missing something else.
jlverry
0
All Courses

From novice to tech pro — start learning today.