# Examples of scalar variables

LotusScript® provides a set of built-in functions that enable you to manipulate scalar values in various ways. A built-in function is a named procedure that is part of the LotusScript® language and typically performs some operation on a value that you pass it, producing a new value, called the return value. Most of these functions fall into one or another of the following four categories:

• Numeric
• String
• Date/time
• Data type conversion

The following examples contain a representative sampling of the LotusScript® numeric and string functions and illustrate some of the things you can do with them. Each example is a Print statement, which causes LotusScript® to display the return value of the particular function.

``````Dim anInt As Integer
anInt% = 6

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

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

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

' Print aDouble# rounded to 1 decimal place.
' Output: 123.7

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

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

' Print the decimal part of 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``````