明示的なデータ型変換

LotusScript® には、値のデータ型を明示的に変換するための組み込み関数が用意されています。これらの関数には、CBool、CByte、CCur、CDat、CDbl、CInt、CLng、CSng、CStr、Cvar があります。

次の例でこれらの関数の使い方を示します。

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

変換に関して、次の点に注意してください。