Domino Code Fragment

Code Name*
Something to watch out for with Str$
Date*
04/29/2024
Source (or email address if you prefer)*
Rlatulippe@romac.com
IP address:.3.137.180.32
Description*
This is documented, but I totally missed it, and I figure others might as well. In Ami Pro, we didn't really have to worry about data types; it was all handled internally for us. But with LotusScript, we sometimes need to do some conversions. An example is changing a number over to it's string representation. For this, you usually use Str$. But watch out! Str$ returns a leading space. So, Str$(1) actually returns " 1". Usually this won't matter, but in some cases it can come back to bite you. Here's some example code where Str$ doesn't work as expected because of the leading space...
Type*
LotusScript
Categories*
(Misc)
Implementation:
Required Client:
Server:
Limitations:
Comments:
Files/Graphics attachments (if applicable): Code:
Dim fooList List As String
fooList("1") = "bar"
fooTag = "1"
Print fooList(fooTag)
fooTag = Str$(1)
Print fooList(fooTag)

When executing the Script, it will fail on the last line because it is actually trying to reference fooList(" 1") instead of fooList("1"). The solution is to use the CStr function, which always returns the literal string conversion of the number. For example, change the above code to the following and it will work ...

Dim fooList List As String
fooList("1") = "bar"
fooTag = "1"
Print fooList(fooTag)
fooTag = CStr(1)
Print fooList(fooTag)