スカラー変数の例

LotusScript® には、さまざまな方法でスカラー値を操作できる組み込み関数一式が用意されています。組み込み関数は、LotusScript 言語の一部である名前付きプロシージャで、通常はユーザーが値を渡すと何らかの処理を実行し、戻り値と呼ばれる新しい値を生成します。これらの関数の多くは、次の 4 つのカテゴリーのいずれかに分類されます。

次の例は、LotusScript の数値関数と文字列関数のサンプルを表しており、これらを使用してできることをいくつか説明しています。それぞれの例で、Print ステートメントを使用して特定の関数の戻り値を表示しています。

Dim anInt As Integer
Dim aDouble As Double
aDouble# = -123.654
anInt% = 6

' Ascertain if aDouble# is a numeric
' data type: True (-1) or False (0).
Print IsNumeric(aDouble#)
' Output: True

' Ascertain if anInt% is positive (1), 
' negative (-1), or neither (0).
Print Sgn(anInt%)
' Output: 1

' Print the absolute value of aDouble#.
Print Abs(aDouble#)
' Output: 123.654

' Print aDouble# rounded to 1 decimal place.
Print Round(aDouble#,1)
' Output: 123.7

' Print the nearest integer equal to or less than aDouble#.
Print Int(aDouble#)
' Output: -124

' Print the integer part of aDouble#.
Print Fix(aDouble#)
' Output: -123

' Print the decimal part of aDouble#.
Print Fraction(aDouble#)
' Output: -.653999999999996

' Print the exponential (base e) of anInt%.
Print Exp(anInt%)
' Output: 403.428793492735

' Print a random whole number between 1 and 5
' by seeding the random number generator,
' calling the Rnd function to generate a random number, 
' and performing various operations on the result.
' First, seed the random number generator.
Randomize
' Generate a random decimal number;
' take its decimal part and round it to one decimal place;
' multiply the result by 10 to make it a one-digit whole
' number; divide that number by 5 and add 1 to the remainder.
' The result is a random whole number between 1 and 5.
Print ((round(Fraction(Rnd),1) * 10) Mod 5) + 1
' Output: a random integer between 1 and 5.

Dim aString As String
Dim theNewString As String

' Assign aString the value (space)(space) abcdef(space)(space).
aString$ = chr$(32) + chr$(32) + "abcdef" + chr$(32) + chr$(32)
Print aString$
' Output: (space) (space) abcdef (space) (space)

' Ascertain the number of characters that aString$ contains.
Print Len(aString$)
' Output: 10

' Strip leading and trailing spaces from aString$.
aString$ = Trim$(aString$)
Print aString$
' Output: abcdef
Print Len(aString$)
' Output: 6

' Convert all the alphabetic characters in aString$ to
' uppercase.
aString$ = UCase$(aString$)
Print aString$
' Output: ABCDEF
' Print the leftmost 3 characters of aString$.
Print Left$(aString$, 3)
' Output: ABC

' Print the position in aString$ where the substring "DE"
' begins.
Print InStr(aString$, "DE")
' Output: 4

' Print the first two characters of the substring that starts
' at the fourth character of aString$.
Print Mid$(aString$,4, 2)
' Output: DE

' Assign theNewString$ a value of a string of 10 asterisks.
theNewString$ = String$(10, "*")
Print theNewString$
' Output: **********

' Starting at the third character of aString$, replace the
' next 2 characters of aString$ with the first 2 characters
' of theNewString$. 
Mid$(aString$,3,2 ) = theNewString$
Print aString$
' Output: AB**EF