Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi,
I have a form with a label control on it. I want to pass this as an argument to a function which does a test. The problem is that this gives me a type mismatch on this form which calls it. If you hover the mouse cursor over the argument which is passed to the function from the calling method in the form, it returns a string value. Any IDeas ? Public Function MyFunction( myLabel as Label ) As Boolean myLabel.Caption = "SomeString" MyFunction = True End Function |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi,
If by form you mean userform then the object type would be MSForms.Label Cheers Andy Goofy wrote: Hi, I have a form with a label control on it. I want to pass this as an argument to a function which does a test. The problem is that this gives me a type mismatch on this form which calls it. If you hover the mouse cursor over the argument which is passed to the function from the calling method in the form, it returns a string value. Any IDeas ? Public Function MyFunction( myLabel as Label ) As Boolean myLabel.Caption = "SomeString" MyFunction = True End Function -- Andy Pope, Microsoft MVP - Excel http://www.andypope.info |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Type mismatch .....
....Calling Form....... Private Sub CommandButton1_Click() Dim c1 As New Class1 c1.addStuff (Label1) End Sub in class1 . . . . . . . . . Public Sub addStuff(ByRef myLabel As MSForms.Label) myLabel.Caption = "Stuff" End Sub "Andy Pope" wrote in message ... Hi, If by form you mean userform then the object type would be MSForms.Label Cheers Andy Goofy wrote: Hi, I have a form with a label control on it. I want to pass this as an argument to a function which does a test. The problem is that this gives me a type mismatch on this form which calls it. If you hover the mouse cursor over the argument which is passed to the function from the calling method in the form, it returns a string value. Any IDeas ? Public Function MyFunction( myLabel as Label ) As Boolean myLabel.Caption = "SomeString" MyFunction = True End Function -- Andy Pope, Microsoft MVP - Excel http://www.andypope.info |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Lose the brackets around the passed argument.
The brackets are actually causing the default value of the label, which is the caption property, to be passed rather than the object. Private Sub CommandButton1_Click() Dim c1 As New Class1 c1.addStuff Label1 End Sub Goofy wrote: Type mismatch ..... ...Calling Form....... Private Sub CommandButton1_Click() Dim c1 As New Class1 c1.addStuff (Label1) End Sub in class1 . . . . . . . . . Public Sub addStuff(ByRef myLabel As MSForms.Label) myLabel.Caption = "Stuff" End Sub "Andy Pope" wrote in message ... Hi, If by form you mean userform then the object type would be MSForms.Label Cheers Andy Goofy wrote: Hi, I have a form with a label control on it. I want to pass this as an argument to a function which does a test. The problem is that this gives me a type mismatch on this form which calls it. If you hover the mouse cursor over the argument which is passed to the function from the calling method in the form, it returns a string value. Any IDeas ? Public Function MyFunction( myLabel as Label ) As Boolean myLabel.Caption = "SomeString" MyFunction = True End Function -- Andy Pope, Microsoft MVP - Excel http://www.andypope.info -- Andy Pope, Microsoft MVP - Excel http://www.andypope.info |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Andy, thanks for your help, this was the problem.
Why do the brackets cause this behaviour, ie the logic behind it.? "Andy Pope" wrote in message ... Lose the brackets around the passed argument. The brackets are actually causing the default value of the label, which is the caption property, to be passed rather than the object. Private Sub CommandButton1_Click() Dim c1 As New Class1 c1.addStuff Label1 End Sub Goofy wrote: Type mismatch ..... ...Calling Form....... Private Sub CommandButton1_Click() Dim c1 As New Class1 c1.addStuff (Label1) End Sub in class1 . . . . . . . . . Public Sub addStuff(ByRef myLabel As MSForms.Label) myLabel.Caption = "Stuff" End Sub "Andy Pope" wrote in message ... Hi, If by form you mean userform then the object type would be MSForms.Label Cheers Andy Goofy wrote: Hi, I have a form with a label control on it. I want to pass this as an argument to a function which does a test. The problem is that this gives me a type mismatch on this form which calls it. If you hover the mouse cursor over the argument which is passed to the function from the calling method in the form, it returns a string value. Any IDeas ? Public Function MyFunction( myLabel as Label ) As Boolean myLabel.Caption = "SomeString" MyFunction = True End Function -- Andy Pope, Microsoft MVP - Excel http://www.andypope.info -- Andy Pope, Microsoft MVP - Excel http://www.andypope.info |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Actually, this is still an issue because I am actually going to need to pass
this to a function and I cant get away with removing the brackets ? "Andy Pope" wrote in message ... Lose the brackets around the passed argument. The brackets are actually causing the default value of the label, which is the caption property, to be passed rather than the object. Private Sub CommandButton1_Click() Dim c1 As New Class1 c1.addStuff Label1 End Sub Goofy wrote: Type mismatch ..... ...Calling Form....... Private Sub CommandButton1_Click() Dim c1 As New Class1 c1.addStuff (Label1) End Sub in class1 . . . . . . . . . Public Sub addStuff(ByRef myLabel As MSForms.Label) myLabel.Caption = "Stuff" End Sub "Andy Pope" wrote in message ... Hi, If by form you mean userform then the object type would be MSForms.Label Cheers Andy Goofy wrote: Hi, I have a form with a label control on it. I want to pass this as an argument to a function which does a test. The problem is that this gives me a type mismatch on this form which calls it. If you hover the mouse cursor over the argument which is passed to the function from the calling method in the form, it returns a string value. Any IDeas ? Public Function MyFunction( myLabel as Label ) As Boolean myLabel.Caption = "SomeString" MyFunction = True End Function -- Andy Pope, Microsoft MVP - Excel http://www.andypope.info -- Andy Pope, Microsoft MVP - Excel http://www.andypope.info |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
If it is a function you can use the brackets if you assign the returned
value to a variable. Private Sub CommandButton1_Click() Dim c1 As New Class1 Dim blnResult As Boolean c1.addStuff Label1 blnResult = c1.addStuff(Label1) End Sub 'Class code Public Function addStuff(ByRef myLabel As MSForms.Label) myLabel.Caption = "Stuff" addStuff = True End Function Goofy wrote: Actually, this is still an issue because I am actually going to need to pass this to a function and I cant get away with removing the brackets ? "Andy Pope" wrote in message ... Lose the brackets around the passed argument. The brackets are actually causing the default value of the label, which is the caption property, to be passed rather than the object. Private Sub CommandButton1_Click() Dim c1 As New Class1 c1.addStuff Label1 End Sub Goofy wrote: Type mismatch ..... ...Calling Form....... Private Sub CommandButton1_Click() Dim c1 As New Class1 c1.addStuff (Label1) End Sub in class1 . . . . . . . . . Public Sub addStuff(ByRef myLabel As MSForms.Label) myLabel.Caption = "Stuff" End Sub "Andy Pope" wrote in message ... Hi, If by form you mean userform then the object type would be MSForms.Label Cheers Andy Goofy wrote: Hi, I have a form with a label control on it. I want to pass this as an argument to a function which does a test. The problem is that this gives me a type mismatch on this form which calls it. If you hover the mouse cursor over the argument which is passed to the function from the calling method in the form, it returns a string value. Any IDeas ? Public Function MyFunction( myLabel as Label ) As Boolean myLabel.Caption = "SomeString" MyFunction = True End Function -- Andy Pope, Microsoft MVP - Excel http://www.andypope.info -- Andy Pope, Microsoft MVP - Excel http://www.andypope.info -- Andy Pope, Microsoft MVP - Excel http://www.andypope.info |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Passing a UDF as an argument to a UDF | Excel Discussion (Misc queries) | |||
Passing argument to another Sub | Excel Programming | |||
Passing Worksheet tab as an argument. | Excel Programming | |||
Need help passing an array as an argument | Excel Programming | |||
VBA - Passing a FUNCTION as an Argument | Excel Programming |