Explicit data type conversion

LotusScript® provides several built-in functions for explicitly converting a value's data type. These functions include CBool, CByte, CCur, CDat, CDbl, CInt, CLng, CSng, CStr, and CVar.

This example illustrates their use:

Dim aString As String
Dim anInt As Integer
Dim aDouble As Double
Dim myFixedPoint As Currency
Dim aVariantV as Variant
 
aString$ = "123"
' Convert the string "123" to a value of type Double.
aDouble# = CDbl(aString$)

' Add the prefix &H to that string, to
' prepare the string for conversion to a
' hexadecimal number. 
aString$ = "&H" & aString$

' Convert the string "&H7B" to an integer, 
' add 12.46 to that integer, explicitly
' convert the result to a value of type Currency,
' and assign it to a variable of type Currency.
' If you omit the step of explicitly converting
' the integer to a value of type Currency, the
' conversion happens automatically when the
' assignment takes place.
myFixedPoint@ = CCur(CInt(aString$) + 12.46)
Print myFixedPoint@
' Output: 135.46

' Explicitly convert a value of type Currency
' to an integer, with automatic rounding off,
' and assign the result to a variable of type
' Integer. If you don't explicitly convert
' the Currency value to an integer,
' conversion (with rounding) happens
' automatically when the assignment takes place.
anInt% = CInt(myFixedPoint@) + 300
Print anInt%
' Output: 435

' Convert an integer to a date value
' and assign it to a Variant variable.
aVariantV = CDat(anInt%)
Print format$(aVariantV, "mm/dd/yyyy")
' Output: 03/10/1901

Some conversion facts to keep in mind:

  • Format[$] converts almost anything to a string.
  • Fix truncates a floating point value to an integer always truncating towards zero.
  • Int truncates a floating point value to an integer smaller than the input value.
  • DateValue converts a string into a date (variant type 7).
  • DateNumber converts a set of numbers into a date value (variant type 7).