![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Hobbyist Programmer
|
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
__________________
And there was much rejoicing... Yay.... |
|
|
|
|
|
#2 |
|
Expert Programmer
|
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 UserControl1.MyLabel.Caption = "hello" |
|
|
|
|
|
#3 |
|
Hobbyist Programmer
|
omg, thank you so much rory, you have no idea how long i spent looking for this.
__________________
And there was much rejoicing... Yay.... |
|
|
|
|
|
#4 |
|
Expert Programmer
|
No probs!
|
|
|
|
|
|
#5 |
|
Hobbyist Programmer
|
uh-oh whenever I run the program, i get this error:
With Variable or Object Variable not set.
__________________
And there was much rejoicing... Yay.... |
|
|
|
|
|
#6 |
|
Expert Programmer
|
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 |
|
|
|
|
|
#7 |
|
Hobbyist Programmer
|
no here is what happens. I call this in my module:
UserControl1.MyLabel.Caption = "hello" I am actually using this in a moudule.
__________________
And there was much rejoicing... Yay.... |
|
|
|
|
|
#8 |
|
Expert Programmer
|
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. |
|
|
|
|
|
#9 |
|
Hobbyist Programmer
|
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!
__________________
And there was much rejoicing... Yay.... |
|
|
|
|
|
#10 |
|
Expert Programmer
|
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. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|