vba - Any difference between '+' and '&' for String concatenation? -


i have realized vba supports operator + concatenate string type, , not &. hence, if

dim string, b string = "stack " b = "overflow" 

the following statements produce same result:

>> + b '--> "stack overflow" >> & b '--> "stack overflow" 

in limited experience have never found in language 2 operators doing always same thing. feel vba tending merge other common languages (using + concatenating strings) still supporting & old-school vb developers.

but doesn't sound technical explanation, i'd ask following question: is there practical difference between 2 operators? case using + rather & yields different result?

what have in mind

a possible "like-answer" have in mind cannot find anywhere in web inspired javascript, can use == , === everywhere same behavior, except the identity (===) operator behaves identically equality (==) operator except no type conversion done, , types must same considered equal.

ok, found it. try this:

debug.print "3" + 4 '--> 7 

and compare this:

debug.print "3" & 4 '--> "34" 

ahh! see difference now? choice of & vs. + affects default type coerces operands of these expressions to.

the + try convert string in numeric and, if possible, treat them such. &, on other hand, keep treating elements string if they're both convertible in numeric.


Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -