AL_XResearch
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:
Many thanks.
Dim strMyName as string
Dim intLengthOfJob as integer
sub myCode(strEmployeeName as string,lngJobAge as long)
end sub
strMyname = "Fred"
myCode strMyName, (intLengthOfJob)
What is this type of implicit argument type conversion actually called (in MS speak) ?Many thanks.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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:
É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:
Or do you mean coercion, by using e.g.
CInt(your_val)