Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Visual Basic (http://www.programmingforums.org/forum18.html)
-   -   Module Access (http://www.programmingforums.org/showthread.php?t=3045)

Cipher Apr 1st, 2005 10:25 PM

Module Access
 
I am making a new usercontrol. I need to access the usercontrol's label which is named lable1

How could I access it from a standard module(.bas)

My usercontrol's name is bob

:


 sub bobcall()
 bob.label1.caption

doesn't seem to work. NEED HELP PLEASE!

Rory Apr 2nd, 2005 9:54 PM

You need to expose label1 in the usercontrol.
Put this in the UserControl:
:

Public Property Get MyLabel() As Object
Set MyLabel = UserControl.Label1
End Property
Public Property Set MyLabel(ByRef NewLabel As Label)
Set UserControl.Label1 = NewLabel
End Property

Then you can do
:

UserControl1.MyLabel.Caption = "hello"

Cipher Apr 3rd, 2005 1:44 PM

omg, thank you so much rory, you have no idea how long i spent looking for this.

Rory Apr 3rd, 2005 8:39 PM

No probs!

Cipher Apr 5th, 2005 9:24 AM

uh-oh whenever I run the program, i get this error:

With Variable or Object Variable not set.

Rory Apr 5th, 2005 2:26 PM

This code seems to work for me...
:

Public Property Get MyLabel() As Label
Set MyLabel = UserControl.Label1
End Property
Public Property Set MyLabel(ByRef NewLabel As Label)
Set UserControl.Label1 = NewLabel
End Property

That kind of error doesn't seem to be possible anywhere in this code: are you sure it's an error with that particular bit?

Cipher Apr 5th, 2005 3:47 PM

no here is what happens. I call this in my module:

UserControl1.MyLabel.Caption = "hello"

I am actually using this in a moudule.

Rory Apr 5th, 2005 3:56 PM

Then you need Form1.[name of control].MyLabel.Caption = "hello"
What VB is trying to do is reference the class rather than the instance on a form, which can't be done.
Let's say I had a usercontrol called ctlMyWidget. The default name for the control when I put it on a form would be ctlMyWidget1. As you're using UserControl1 for the class name, the default name is actually UserControl11 , which is where the problem is.

Cipher Apr 6th, 2005 10:00 AM

ok..as soon as I get home I will test it. Thxs once again rory.

Also, why won't it let me use APIs

I put an API in my code and it says,: User-Type not defined. And highlights the API..

My Visual Basic is such as POS!

Rory Apr 6th, 2005 4:23 PM

Your question about the API: My gues is you're using an API such as GetCursorPos that uses a custom type in its argument list. In this case, the custom POINTAPI type is used:

:

Public Type POINTAPI
x as long
y as long
End Type


Look through the specific API declaration for any user defined types and ensure you have them defined in code as well. If you can't find their definition, googling for articles on the API in question will usually also provide the necessary types as well.


All times are GMT -5. The time now is 5:28 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC