I would like to use numbers in 3-digit format: for example 1 to 001, 2 to 002, 10 to 010, 11 to 011 and so on.
In details: I would like to get the following string format W20HYaaa where aaa is a number between 1 and 255.
How could I do that?
Sorry, I must be missing your point. I quite clearly said "If both operands are strings". If one isn't a string, such as null, then it won't concatenate like & (which isn't overloaded)
Heck, even if you ignore the ability to concatenate, + is overloaded. It knows how to add integers, longs, singles, and doubles. You may argue that yes, that's what addition is, covers all of those. But VBA's + operator works differently depending on the type of the operands, which is typical of overloading (and concatenation is just an version of that)
Indeed most of the maths operators can be considered overloaded. For example
Msgbox 256 * 256
will error because the operand sees two integer operands and so does an integer calculation, and overflows. Change either operand to a long (e.g. MsgBox 256 * 256&), and the operator does a long calculation instead. This is a classic example of what the object-orientated world sometimes calls ad hoc polymorphism.
Very good point. Even though I'm aware of such limitations (type overflows), I guess I just take most operators for granted. However, I'm keen to it now
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.