When concatenating strings, there are multiple valid methods of inserting spaces.
Space Function:
Print "A" & Space(1) & "B"
A B
VS
Quotes:
Print "A" & " " & "B"
A B
VS
Chr:
Print "A" & Chr(32) & "B"
A B
All three methods yield the same result. The only place where I found Space beneficial was when using a variable for the number of spaces.
Space( <expression of number - len(var)> )
Can anyone provide any insight on why one method is better than another?
As suggested, they all yield the same result when compiled. There might be situational benefit such as:
1) Space()
- Good when multiple space is needed.
Space(100) is better than chr(32) & chr(32) & chr(32) & ...
2) " "
- Visual expression that is easy to understand, esp for new vba learner
EDIT: Also faster than a method call, thanks to Blackhawk to point out
3) chr()
- character expression that could be used to print particular character to say a text file. E.g. printing Enter/Return with chr(10). I don't see any obvious benefit for print space however
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With