Wednesday, February 16, 2011

Booleans (and more) as Strings

Did you know you can pass a boolean value to the Str function? You can. It will return the string "True" or "False". For example, the following code displays the string "True" in a message box:

Dim b as Boolean
b = True
Msgbox Str(b)

But that's not all. You can also pass Date and Color objects to the Str function as well. Pass a Date and you'll get the SQL formatted date back (YYY-MM-DD) and with Color, Str returns the color in hex form as a string. You can learn about this in the documentation for the Str function.

This tip was suggested by Jean-Luc Arnaud. Thanks Jean-Luc!

No comments: