ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   type mismatch? (https://www.excelbanter.com/excel-programming/326580-type-mismatch.html)

Gixxer_J_97[_2_]

type mismatch?
 
hi all!

i have a sub defined in a module:
public sub myFunc(a as string, b as string, optional c as integer, optional
d as label)
.....
end sub

calling this from a userform:

call myFunc(a,b,c,d)

where
a and b are TextBox (defined in the UserForm)
c is an integer defined private c as integer
d is a Label (defined in the userform)

all variables have a value

i am getting a type mismatch error on this call
call myFunc(a,b,c,d)
..... why?
(i have also tried a.value, a.text, cstr(a) and that hasn't worked. i've
also tried cint(c)


Tom Ogilvy

type mismatch?
 
try

public sub myFunc(a as string, b as string, _
optional c as integer, optional d as Object)


--
Regards,
Tom Ogilvy




"Gixxer_J_97" wrote in message
...
hi all!

i have a sub defined in a module:
public sub myFunc(a as string, b as string, optional c as integer,

optional
d as label)
....
end sub

calling this from a userform:

call myFunc(a,b,c,d)

where
a and b are TextBox (defined in the UserForm)
c is an integer defined private c as integer
d is a Label (defined in the userform)

all variables have a value

i am getting a type mismatch error on this call
call myFunc(a,b,c,d)
.... why?
(i have also tried a.value, a.text, cstr(a) and that hasn't worked. i've
also tried cint(c)




Jim Thomlinson[_3_]

type mismatch?
 
If that doesn't work... (Probably will. Tom is usually right...) try

public sub myFunc(a as variant, b as variant, optional c as variant, optional
d as variant)

And then place a watch on a, b, c, and d just to see what you really have
passed. It can be easy to pass the wrong thing.

HTH


"Tom Ogilvy" wrote:

try

public sub myFunc(a as string, b as string, _
optional c as integer, optional d as Object)


--
Regards,
Tom Ogilvy




"Gixxer_J_97" wrote in message
...
hi all!

i have a sub defined in a module:
public sub myFunc(a as string, b as string, optional c as integer,

optional
d as label)
....
end sub

calling this from a userform:

call myFunc(a,b,c,d)

where
a and b are TextBox (defined in the UserForm)
c is an integer defined private c as integer
d is a Label (defined in the userform)

all variables have a value

i am getting a type mismatch error on this call
call myFunc(a,b,c,d)
.... why?
(i have also tried a.value, a.text, cstr(a) and that hasn't worked. i've
also tried cint(c)





Gixxer_J_97[_2_]

type mismatch?
 
thanks guys - the 'object' worked

i guess my question now is why it wouldn't work with Label?



"Jim Thomlinson" wrote:

If that doesn't work... (Probably will. Tom is usually right...) try

public sub myFunc(a as variant, b as variant, optional c as variant, optional
d as variant)

And then place a watch on a, b, c, and d just to see what you really have
passed. It can be easy to pass the wrong thing.

HTH


"Tom Ogilvy" wrote:

try

public sub myFunc(a as string, b as string, _
optional c as integer, optional d as Object)


--
Regards,
Tom Ogilvy




"Gixxer_J_97" wrote in message
...
hi all!

i have a sub defined in a module:
public sub myFunc(a as string, b as string, optional c as integer,

optional
d as label)
....
end sub

calling this from a userform:

call myFunc(a,b,c,d)

where
a and b are TextBox (defined in the UserForm)
c is an integer defined private c as integer
d is a Label (defined in the userform)

all variables have a value

i am getting a type mismatch error on this call
call myFunc(a,b,c,d)
.... why?
(i have also tried a.value, a.text, cstr(a) and that hasn't worked. i've
also tried cint(c)





Tom Ogilvy

type mismatch?
 
Read the help on Function under the description of Optional, then below that
look at the as type narrative.


--
Regards,
Tom Ogilvy


"Gixxer_J_97" wrote in message
...
thanks guys - the 'object' worked

i guess my question now is why it wouldn't work with Label?



"Jim Thomlinson" wrote:

If that doesn't work... (Probably will. Tom is usually right...) try

public sub myFunc(a as variant, b as variant, optional c as variant,

optional
d as variant)

And then place a watch on a, b, c, and d just to see what you really

have
passed. It can be easy to pass the wrong thing.

HTH


"Tom Ogilvy" wrote:

try

public sub myFunc(a as string, b as string, _
optional c as integer, optional d as Object)


--
Regards,
Tom Ogilvy




"Gixxer_J_97" wrote in message
...
hi all!

i have a sub defined in a module:
public sub myFunc(a as string, b as string, optional c as integer,
optional
d as label)
....
end sub

calling this from a userform:

call myFunc(a,b,c,d)

where
a and b are TextBox (defined in the UserForm)
c is an integer defined private c as integer
d is a Label (defined in the userform)

all variables have a value

i am getting a type mismatch error on this call
call myFunc(a,b,c,d)
.... why?
(i have also tried a.value, a.text, cstr(a) and that hasn't worked.

i've
also tried cint(c)








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

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