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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

wormboy__6Commented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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 Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.