Link to home
Start Free TrialLog in
Avatar of AL_XResearch
AL_XResearchFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Excel VBA - Terinology: Argument type matching

I am trying to explain to a colleague about using rounded brackets to covert the type of a passed parameter to match the type expected by the code being called. For example:
Dim strMyName as string
Dim intLengthOfJob as integer

sub myCode(strEmployeeName as string,lngJobAge as long)
end sub

strMyname = "Fred"
myCode strMyName, (intLengthOfJob)

Open in new window

What is this type of implicit argument type conversion actually called (in MS speak) ?

Many thanks.
Avatar of Jon von der Heyden
Jon von der Heyden
Flag of United Kingdom of Great Britain and Northern Ireland image

Type declaration perhaps?

Or do you mean coercion, by using e.g.

CInt(your_val)
Avatar of Éric Moreau
Well in your case, it is an implicit type cast because an integer fits into long without any problems. Adding or not parenthesis in this case won't do anything.
ASKER CERTIFIED SOLUTION
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of AL_XResearch

ASKER

Jon von der Heyden: No that would be an explicit type coercion - and not what I am asking about.

Éric Moreau & aikimark: Thank you !! That was the brain reboot I was looking for.

Of course if you pass a long as a parameter that is expecting an int you will get a "Type Mismatch" error (even if the value is 5 - i.e, a valid number for both data types) but if you enclose it in brackets you are passing by value (and hence referring to a different memory location) and you don't have the error.

I knew it wasn't doing an implicit type conversion as such but I couldn't remember what it actually did - only that it usually 'worked' when the data was valid for the intended argument type - and without the term I couldn't look it up.

Éric I am afraid your link didn't produce a valid web page for me but once my memory had clicked I was able to find the link below: