ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Passing a Control as an Argument (https://www.excelbanter.com/excel-programming/376369-passing-control-argument.html)

Goofy

Passing a Control as an Argument
 
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

Passing a Control as an Argument
 
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

Goofy

Passing a Control as an Argument
 
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

Passing a Control as an Argument
 
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

Goofy

Passing a Control as an Argument
 
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




Goofy

Passing a Control as an Argument
 
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

Passing a Control as an Argument
 
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

Goofy

Passing a Control as an Argument
 
Unfotunately, I get the same error message, as soon as the damn control is
inside those brackets it refuses to work. Progress is the name of the Label
in the form.PCM is the object whioch contains the function I am trying to
pass the Label to

Dim stage1Result As Boolean
stage1Result = pcm.ownerValidationReport(ws, we, drpCells.Value,
ScheduleVerbIntegrety, False, True, progress)


Thanks for your help


"Andy Pope" wrote in message
...
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




Goofy

Passing a Control as an Argument
 

I see what you are saying, but I need the result and the passing to happen
at the same time. or maybe I can change this to a sub and have it pass back
the result by reference.


"Andy Pope" wrote in message
...
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




Andy Pope

Passing a Control as an Argument
 
So what do the function ownerValidationReport argument list look like?
And do the arguments you are passing in match those the function is
expecting?

Cheers
Andy

Goofy wrote:
Unfotunately, I get the same error message, as soon as the damn control is
inside those brackets it refuses to work. Progress is the name of the Label
in the form.PCM is the object whioch contains the function I am trying to
pass the Label to

Dim stage1Result As Boolean
stage1Result = pcm.ownerValidationReport(ws, we, drpCells.Value,
ScheduleVerbIntegrety, False, True, progress)


Thanks for your help


"Andy Pope" wrote in message
...

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





--

Andy Pope, Microsoft MVP - Excel
http://www.andypope.info

Goofy

Passing a Control as an Argument
 
I changed it to a sub, to see if I could use the parameters passed to get
the result, but I get the same
problem.

'Calling
Dim stage1Result As Boolean
pcm.ownerValidationReport ws, we, drpCells.Value, ScheduleVerbIntegrety,
False, True, progress, stage1Result
If Not stage1Result Then


'Called
Public Sub ownerValidationReport(weekStart As Integer, weekEnd As Integer,
cell As String, validation As validationType, includeSuccesses As Boolean,
loggingContinued As Boolean, ByRef progressLabel As msForms.Label, result As
Boolean)

Dim spreadSheetYear As Integer
Dim allWeeks As Boolean
Dim thereWereErrors As Boolean







"Andy Pope" wrote in message
...
So what do the function ownerValidationReport argument list look like?
And do the arguments you are passing in match those the function is
expecting?

Cheers
Andy

Goofy wrote:
Unfotunately, I get the same error message, as soon as the damn control
is inside those brackets it refuses to work. Progress is the name of the
Label in the form.PCM is the object whioch contains the function I am
trying to pass the Label to

Dim stage1Result As Boolean
stage1Result = pcm.ownerValidationReport(ws, we, drpCells.Value,
ScheduleVerbIntegrety, False, True, progress)


Thanks for your help


"Andy Pope" wrote in message
...

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





--

Andy Pope, Microsoft MVP - Excel
http://www.andypope.info




Goofy

Passing a Control as an Argument
 
Andy,

I have to go now, so I will read any reply you send tomorrow morning.

Many Thanks


"Goofy" wrote in message
...
I changed it to a sub, to see if I could use the parameters passed to get
the result, but I get the same
problem.

'Calling
Dim stage1Result As Boolean
pcm.ownerValidationReport ws, we, drpCells.Value,
ScheduleVerbIntegrety, False, True, progress, stage1Result
If Not stage1Result Then


'Called
Public Sub ownerValidationReport(weekStart As Integer, weekEnd As Integer,
cell As String, validation As validationType, includeSuccesses As Boolean,
loggingContinued As Boolean, ByRef progressLabel As msForms.Label, result
As Boolean)

Dim spreadSheetYear As Integer
Dim allWeeks As Boolean
Dim thereWereErrors As Boolean







"Andy Pope" wrote in message
...
So what do the function ownerValidationReport argument list look like?
And do the arguments you are passing in match those the function is
expecting?

Cheers
Andy

Goofy wrote:
Unfotunately, I get the same error message, as soon as the damn control
is inside those brackets it refuses to work. Progress is the name of the
Label in the form.PCM is the object whioch contains the function I am
trying to pass the Label to

Dim stage1Result As Boolean
stage1Result = pcm.ownerValidationReport(ws, we, drpCells.Value,
ScheduleVerbIntegrety, False, True, progress)


Thanks for your help


"Andy Pope" wrote in message
...

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
l...


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




--

Andy Pope, Microsoft MVP - Excel
http://www.andypope.info






Andy Pope

Passing a Control as an Argument
 
Hi,

I get a compile error due to the Validation variable. It does not
understand what validationType is.

But if I use Variant instead I can get it to work as either sub or function.

If you want to email me your code off NG you can.

Cheers
Andy

Goofy wrote:
I changed it to a sub, to see if I could use the parameters passed to get
the result, but I get the same
problem.

'Calling
Dim stage1Result As Boolean
pcm.ownerValidationReport ws, we, drpCells.Value, ScheduleVerbIntegrety,
False, True, progress, stage1Result
If Not stage1Result Then


'Called
Public Sub ownerValidationReport(weekStart As Integer, weekEnd As Integer,
cell As String, validation As validationType, includeSuccesses As Boolean,
loggingContinued As Boolean, ByRef progressLabel As msForms.Label, result As
Boolean)

Dim spreadSheetYear As Integer
Dim allWeeks As Boolean
Dim thereWereErrors As Boolean







"Andy Pope" wrote in message
...

So what do the function ownerValidationReport argument list look like?
And do the arguments you are passing in match those the function is
expecting?

Cheers
Andy

Goofy wrote:

Unfotunately, I get the same error message, as soon as the damn control
is inside those brackets it refuses to work. Progress is the name of the
Label in the form.PCM is the object whioch contains the function I am
trying to pass the Label to

Dim stage1Result As Boolean
stage1Result = pcm.ownerValidationReport(ws, we, drpCells.Value,
ScheduleVerbIntegrety, False, True, progress)


Thanks for your help


"Andy Pope" wrote in message
...


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
l...



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



--

Andy Pope, Microsoft MVP - Excel
http://www.andypope.info





--

Andy Pope, Microsoft MVP - Excel
http://www.andypope.info

Goofy

Passing a Control as an Argument
 

Hi Andy,

Thanks for all your help yesterday. In the end it was nothing to do with the
Label being passed, the error was due to something further down, I was
clicking on Step Over not step in, so I assumed the error was at the calling
line when in reality it was not.


Regards - Goofy





"Andy Pope" wrote in message
...
Hi,

I get a compile error due to the Validation variable. It does not
understand what validationType is.

But if I use Variant instead I can get it to work as either sub or
function.

If you want to email me your code off NG you can.

Cheers
Andy

Goofy wrote:
I changed it to a sub, to see if I could use the parameters passed to get
the result, but I get the same
problem.

'Calling
Dim stage1Result As Boolean
pcm.ownerValidationReport ws, we, drpCells.Value,
ScheduleVerbIntegrety, False, True, progress, stage1Result
If Not stage1Result Then


'Called
Public Sub ownerValidationReport(weekStart As Integer, weekEnd As
Integer, cell As String, validation As validationType, includeSuccesses
As Boolean, loggingContinued As Boolean, ByRef progressLabel As
msForms.Label, result As Boolean)

Dim spreadSheetYear As Integer
Dim allWeeks As Boolean
Dim thereWereErrors As Boolean







"Andy Pope" wrote in message
...

So what do the function ownerValidationReport argument list look like?
And do the arguments you are passing in match those the function is
expecting?

Cheers
Andy

Goofy wrote:

Unfotunately, I get the same error message, as soon as the damn control
is inside those brackets it refuses to work. Progress is the name of the
Label in the form.PCM is the object whioch contains the function I am
trying to pass the Label to

Dim stage1Result As Boolean
stage1Result = pcm.ownerValidationReport(ws, we, drpCells.Value,
ScheduleVerbIntegrety, False, True, progress)


Thanks for your help


"Andy Pope" wrote in message
.. .


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
bl...



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



--

Andy Pope, Microsoft MVP - Excel
http://www.andypope.info





--

Andy Pope, Microsoft MVP - Excel
http://www.andypope.info




Andy Pope

Passing a Control as an Argument
 
Ok, thanks for letting us know.

Cheers
Andy

Goofy wrote:
Hi Andy,

Thanks for all your help yesterday. In the end it was nothing to do with the
Label being passed, the error was due to something further down, I was
clicking on Step Over not step in, so I assumed the error was at the calling
line when in reality it was not.


Regards - Goofy





"Andy Pope" wrote in message
...

Hi,

I get a compile error due to the Validation variable. It does not
understand what validationType is.

But if I use Variant instead I can get it to work as either sub or
function.

If you want to email me your code off NG you can.

Cheers
Andy

Goofy wrote:

I changed it to a sub, to see if I could use the parameters passed to get
the result, but I get the same
problem.

'Calling
Dim stage1Result As Boolean
pcm.ownerValidationReport ws, we, drpCells.Value,
ScheduleVerbIntegrety, False, True, progress, stage1Result
If Not stage1Result Then


'Called
Public Sub ownerValidationReport(weekStart As Integer, weekEnd As
Integer, cell As String, validation As validationType, includeSuccesses
As Boolean, loggingContinued As Boolean, ByRef progressLabel As
msForms.Label, result As Boolean)

Dim spreadSheetYear As Integer
Dim allWeeks As Boolean
Dim thereWereErrors As Boolean







"Andy Pope" wrote in message
...


So what do the function ownerValidationReport argument list look like?
And do the arguments you are passing in match those the function is
expecting?

Cheers
Andy

Goofy wrote:


Unfotunately, I get the same error message, as soon as the damn control
is inside those brackets it refuses to work. Progress is the name of the
Label in the form.PCM is the object whioch contains the function I am
trying to pass the Label to

Dim stage1Result As Boolean
stage1Result = pcm.ownerValidationReport(ws, we, drpCells.Value,
ScheduleVerbIntegrety, False, True, progress)


Thanks for your help


"Andy Pope" wrote in message
. ..



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
. gbl...




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
l...





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



--

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


All times are GMT +1. The time now is 09:31 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com