0% found this document useful (0 votes)
27 views42 pages

Basic LotusScript Programming Guide

The Basic LotusScript Course introduces LotusScript as a powerful scripting language derived from BASIC, enabling object-oriented application development across multiple platforms. It highlights the advantages of LotusScript, including its ease of learning, multi-platform compatibility, and integration with Domino, while also discussing when to use scripts versus formulas. The course covers fundamental concepts such as script structure, data types, variable declaration, and the Integrated Development Environment (IDE) for writing and debugging scripts.

Translated by

ScribdTranslations
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views42 pages

Basic LotusScript Programming Guide

The Basic LotusScript Course introduces LotusScript as a powerful scripting language derived from BASIC, enabling object-oriented application development across multiple platforms. It highlights the advantages of LotusScript, including its ease of learning, multi-platform compatibility, and integration with Domino, while also discussing when to use scripts versus formulas. The course covers fundamental concepts such as script structure, data types, variable declaration, and the Integrated Development Environment (IDE) for writing and debugging scripts.

Translated by

ScribdTranslations
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Basic LotusScript Course

COURSE
LOTUS SCRIPT
BASIC

Page 1
Curso LotusScript Básico

1.- INTRODUCTION

LotusScript is a scripting language compatible with BASIC with some extensions of


powerful languages that enable the development of object-oriented applications.
LotusScript allows for the design of more complex scripts in more places than macros.
traditional. LotusScript and its development tools provide an environment of
common programming in all Lotus applications on all platforms that
they support Lotus.

LotusScript offers developers a wide variety of features that


they expect a modern programming language that is completely object-oriented.
Its interface with Domino is done through predefined object classes. Domino
supervises the compilation and loading of the scripts that create the users and
automatically includes the definition of Domino object classes. This allows
to develop the code of the programs in an efficient way.

While the @functions are ideal for coding a simple logic for example, to
the translation or validation of fields, LotusScript provides the ability to create loops,
build 'case' statements, branches, subroutines, etc.

The Integrated Development Environment (IDE) also performs indentation.


automatic, which follows the logic of the program as in IF-THEN-ELSE statements and
loops, and this makes programs easier to read and maintain.

Fig. 1 - Example of IDE indentation

Page 2
Basic LotusScript Course

The hierarchy of LotusScript classes represents the control flow that you follow in the
user interface if you go from the icon of a database to a view, up to a
document and even a specific field within this document. For example, if you are
programming in LotusScript, you would start with the UIWorkspace class and go down
to the UIDocument class that represents the currently open document. Once
Once you have initialized these objects, you will have access to the fields of the document.

The same principle applies if you are programming with the back-end classes of Domino,
what do the objects you might want to work with represent that are not in the
user interface. You would start in the NotesSession class and go down to the class
NotesDatabase and the NotesDocument class, but we will see this in more detail.
in the Domino object model.

Page 3
Basic LotusScript Course

2.- ADVANTAGES OF LOTUSSCRIPT

LotusScript offers the following advantages:

Derived from BASIC

Since LotusScript is derived from BASIC, it is easy to learn, especially for


Visual Basic users. Complicated scripts can be written using conditions.
branching, subroutines, loops, and other language conventions.

Multi-platform

LotusScript is a scripting language similar to multi-platform BASIC. It works in


platforms like Windows, Macintosh, OS/2, UNIX, OS/390, and AS400. The scripts
developed on Windows run unchanged on any other platform
supported. This portability is important when desktop applications are converted into
applications for group work and the documents are sent by email or are
shared by other users.

Object-oriented

Lotus products bring us a series of classes and objects that are available for
LotusScript. Scripts can be written to access and manipulate these objects. The
scripts are handled by events, either an action, clicking on an object or
button, opening a document or a view.

OLE support

Using LotusScript, Notes can be the perfect container for documents of


SmartSuite and other OLE applications like Microsoft Office.

Coexistence with @functions

Lotus continues to support @functions and LotusScript works well with them.

Integrated Development Environment

The Integrated Development Environment for LotusScript (IDE) provides an interface for
create, edit, and debug the scripts, and also review the variables and properties of the
classes. The IDE allows you to write more complex scripts in Notes.

LotusScript Libraries

Functions and class libraries can be created and reused in other applications.
through the USE statement.

Page 4
Basic LotusScript Course

3.- Use of Scripts versus the use of formulas

In general, formulas are better for working with the object that the user
is currently working, for example, to give a default value to a field
or to determine the selection criteria for a view. Scripts are best used for
access existing objects, for example, to change a value in a document-based
in values of other documents. The scripts provide some capabilities that the formulas
no dan, like the ability to manipulate rich text fields. The formulas give
a better performance in some situations and are convenient for applications
simple.

When we are asked to decide when to use LotusScript or formulas for a task
determined, usually depends on its complexity. It is necessary to consider
certain things that we detail below.

LotusScript is not available in the following areas of Notes:

View Design: form formulas, selection formulas, formulas for


columns.

Form design: view titles, section titles, access to sections,


insertion of subforms, hiding of paragraphs.

Field design: default values, translation of entered data,


validation of entered data, calculated values.

Keyword field formulas (radio buttons, checkboxes,


dialog box, etc.).

SmartIcons Formulas

Try to use the following information to help you determine when to use
formulas or LotusScript to perform some programming task in Notes:

Use a formula when there is a @function or @command that performs the task.

Uses LotusScript for complex process control and for loops (version 6 of
Domino already has @formulas to work with loops, however it is usually much more
it is advisable to implement these with LotusScript.

Use LotusScript to access and manipulate data stored in documents,


particularly for access between multiple documents and multiple databases. By
for example, LotusScript is a good tool for creating an agent that searches all
the databases in the work area and returns information such as the size of the databases
of data, percentage used, number of documents, etc. LotusScript is also a
good tool to perform a text search across multiple documents and carry out
an action with the search results.

Use LotusScript to perform tasks that the formula language does not support.

Page 5
Basic LotusScript Course

Should I use front-end or back-end classes? Front-end classes use the same
Domino code like the equivalent @commands, so LotusScript will not execute
better than the formulas when these classes are used. The back-end classes without
embargo, they use a different code and perform better than their @functions
equivalents. For example, avoid using the NotesUIDocument class from the front-end to
update many fields. The NotesDocument class of the back-end is
much faster and allows you to assign data types and add new (hidden) fields.
The front-end class allows updating only fields that already exist in the form, and
it allows you to insert only text in the field, as does the
@Command([EditInsertText]). In addition, the front-end classes will not work in
agents programmed to execute by the server, only in agents that run on the
user workstation, for example from the menu.

If you use many @functions in a sequential formula, try to change the


formulas to LotusScript code. However, the formulas that need only one
@function, like @Command([FilePrint]), are more efficient and have a better
performance that scripts do the same.

Page 6
Basic LotusScript Course

4.- Scripts and Statements

A script consists of one or more lines of text called statements. The statements
They are processed sequentially by the compiler. LotusScript interprets the newline character.
line (return of car how the final of a sentence.

Each statement is generally written on one line, but some extend to more than
a line. To continue a single statement over multiple lines, use the dash character
underscore (_) as line continuation character.

To use the line continuation character:


Put a blank space before
Use it at the end of a line of text.

For example, the following script shows 2 statements. The first is contained in a
one line and the second in two:

Dim tNombre1 As String


Dim tNombre2
As String

Identifying the elements of language

The elements of language used to construct sentences and scripts are:

Identifiers
Keywords
Literals and constants
Operators

Identifiers

They are names given to individual elements of the script. Variables, constants and
functions are some of the elements that require a name or identifier.
When creating identifiers, the following rules should be taken into account:

The first character must be a letter


Valid characters are letters, digits, and the underscore character (_)
The valid number of characters can be from 1 to 40
Characters with ANSI codes above 127 (those outside the ASCII range) are
legal.

Some classes of Lotus products and OLE classes can define properties or methods.
whose identifiers use illegal characters for LotusScript identifiers. In
in these cases, such characters must be prefixed with a tilde (̃~) to make
that the character is valid.

Example:

Page 7
Basic LotusScript Course

Call [Link]$ ' Illegal


Call [Link]~$ ' Legal

Names do not discriminate between uppercase and lowercase letters. For example, 'NEdad' is the same as
nedad

Examples of valid identifiers are:

xyz
i
A_27
FirstLastName
T1234_567

Keywords

They are words that LotusScript reserves for its own use. They have a meaning or
specific function in the LotusScript language. You cannot use these words in
different contexts than those for which they were created. These refer to sentences, functions
predefined, predefined constants, and data types. The keywords 'New' and
'Delete' can be used to name subs (procedures) that you define in the script.
Other keywords are not names but appear in the sentences for example:
'NoCase' or 'Binary'. Some of the operators in LotusScript are reserved words.
like 'Eqv' and 'Imp'.

Literals

They are data values that do not change. The values of literals can be numbers or
chains.
Strings are written in quotes ( " " ), a pair of vertical bars ( | | ) or a pair
of keys ( { } ), but it is most common to use quotes.

The following values are examples of literals:


327 ' Numeric literal
Sonia Agüero

Constants

These are names used to represent values that will not change in the scripts.
One might think that a constant is a name we give to a fixed literal value.
Constants are usually used to name values in Spanish or English.
which are understood by the computer.
Constants can be:

- Predefined as part of LotusScript and these will always be available in a


application. The following table shows the constants predefined by LotusScript:

Constant Value
NULL It is a special value that represents that the information is

Page 8
Basic LotusScript Course

"unknown" or "that is missing". It can only be assigned to


variant type variables.
EMPTY It is the initial value of a Variant variable. If it is converted
a string, its value is " " (an empty string).
NOTHING It is the initial value of a reference variable to a
object.
TRUE y FALSE The numerical values are -1 and 0 respectively. These
values are returned by all operations of
comparison and logics.
PI The ratio of the circumference of a circle to its
diameter. (3.14159265358979)

- Predefined by LotusScript, in the [Link] file. These constants are


available in a module only when the module explicitly includes the file in the
that are defined. You need to use the %Include directive to incorporate the file into
the application in a module that must be loaded when you need these constants. The
the syntax to include this file is:

%Include "[Link]".

Defined by the application developer, in a module of the application or in a


file that is explicitly included in a module. The reserved word is used.
'Const'. For example:

Const X = 123.45 ' Define a Double constant


Const Y = 123 ' Define an Integer constant
Const NAME = "Sonia" ' Define a String constant

Operators

As in other programming languages, operators are symbols or keywords.


that are used to manipulate data in expressions. The value of an expression is
determined by the order in which their parts are evaluated. Operators have a precedence order.
precedence, those with higher precedence are evaluated before those with lower precedence and
those at the same level are evaluated from left to right.

To skip the normal order of evaluation in an expression, parentheses are used.


The subexpressions in parentheses are evaluated before other parts of the expression.
left to right. The following table summarizes the order of precedence of the
existing operators. Operators on the same line have the same precedence.
In order from highest to lowest, the operators of LotusScript are:

Operator Type Operator Operation


Arithmetic ^ Exponentiation
- Unitary denial
*, / Multiplication, point division
floating

Page 9
Basic LotusScript Course

\ Division of integers
mod Modulo division (remainder)
-, + Subtract, add
Concatenation & String concatenation
Relational =, <>, ><, <, Number and string comparison
(Comparison) <=, =<, >, >=, ‘Igual que’, ‘No igual que’, ‘No igual
=>, Like ["greater than","less than","less than or equal to"]
{"menor o igual que":"less than or equal to","mayor que":"greater than"}

greater than or equal to


what, Contains (pairing of
substrings)
Comparison of Is, IsA Check the type of objects, it refers to
object reference to the same object
Same precedence
than the relational ones)
Logical Not Logical negation
And Boolean or bitwise And
Or Boolean or bitwise Or
Xor Boolean or exclusive bitwise
Eqv Boolean or bitwise equivalence
logic
Imp Boolean or bitwise implication
logic
Assignment = Assignment

Page 10
Basic LotusScript Course

5.- Identifying the types of data

The basic unit that programs work with is data. Data is another
word for values. Values can be of different types, such as numbers or letters.
The data type of a value helps in LotusScript to identify:

How much memory should be allocated to store and manipulate the value.
What operations can be performed with the value.

LotusScript recognizes scalar data types:


- Numéricos: datos que pueden utilizarse para hacer cálculos
String (chains): data representing any number of letters.

In addition, LotusScript recognizes aggregate data types, such as arrays from which
we will talk later. There is also a data type 'Variant', which can be used
to represent any of the other types of non-aggregated data.

Scalar data types

The string and numeric data types represent data that has a single value in
any moment. These are known as scalar data types:

Tipo de dato Palabra clave Sufijo Description Values


Integer INTEGER % Numbers without -32.768 to +32.767
fractional component
Long LONG & Long integers -2,147,483,648 to
+2,147,483,647
Double DOUBLE # Point values + or - 17 digits with a
double floating floating point
precision
Single SINGLE ! Point values + or - 7 digits with a
floating floating point
Currency CURRENCY @ Numerical data, Floating point format
representing values with up to 15 digits to the
monetary to the left of the point
decimal y 4 to the right.
String STRING $ Character strings 0 to 32k characters
of variable size
Fixed String STRING * n None Character strings 0 to 32k characters
of a size
specific

Page 11
Basic LotusScript Course

6.- Declaration and Assignment of Variables


Scripts manipulate various types of data using constants and variables. A variable,
It is a memory location that has a name and stores the value of a data.
assigned to that location. The value of a variable can change during execution
of the program contrary to the constants that have their fixed value. To the process of
defining the name of a variable and its data type is called 'declaration of
variables.

Follow these steps to declare a variable and assign it a value:


1. Declare the variable using the 'DIM' statement.
2. Assign data to the variable one or many times.

Usando la sentencia DIM

Syntax
Use one of the two methods to declare a variable:
DIM variableName AS data_type
DIM variableName(character suffix)

Example:
Dim address as String
Of interest! The variable 'interes' has been declared as type SINGLE

Assigning data

Once the variable has been defined, use the assignment operator, the symbol
equal (=), to assign data to the variable.
Example:
The following statements show the definition of a variable, assignment of a value
and show it:

Dim name as String


nombre = “Pepe Perez”
MessageBox(name)

Communication with users

With LotusScript, we have 2 ways to communicate with users:


The InputBox function
The MessageBox function

Requesting values (InputBox Function)


The InputBox function creates a dialog box that asks the user to enter something. The
the indicator used to request information is defined by the user. The values
entered are returned to the script.

Page 12
Basic LotusScript Course

The syntax for the InputBox function is:


InputBox('indicator')

Showing messages (MessageBox function)


The MessageBox function opens a dialog box that displays information to the
user, wait for a response and return information about that response.
The simple syntax for the MessageBox function is:
MessageBox("This is the message")

Returning response values


The MessageBox function also returns information about a response.

Example:
The following script shows a message box with a Yes button and a No button and returns
a value indicating which button was selected:

DIM response AS INTEGER


respuesta = MessageBox(“¿Desea continuar?”, 4)
MessageBox(response)

To do this, it is necessary for us to know the complete syntax of the MessageBox function.
where we pass each button that we want to be displayed as a parameter to the
function and each button returns a specific integer value, following this table:

Constant Name Value


Buttons that shows
OK 0
OK (Accept)
OK_CANCEL 1
OK y Cancel (Aceptar y Cancelar)
MB_ABORTRETRYIGNORE 2
Abort, Retry, and Ignore
Omit
MB_YESNOCANCEL 3 Yes, No, y Cancel (Sí, No y Cancelar)
MB_YESNO 4 Yes and No
MB_RETRYCANCEL 5 Retry y Cancel (Reintentar y Cancelar)
Button Table of the MessageBox function

Likewise, you can customize the icon that will be displayed in the box with the message,
either to indicate a notice, error, etc.

Constant Name Valor


Displayed icon
MB_ICONSTOP 16 Stop Sign
MB_ICONQUESTION 32 Brand of
Interrogation
MB_ICONEXCLAMATION 48 Exclamation mark
MB_ICONINFORMATION 64 Information
Icon Table of the MessageBox function

The complete syntax of the MessageBox function is as follows:

Page 13
Basic LotusScript Course

MessageBox (message[, [buttons + icon + default + mode] [, Title]])


Where:
Mensaje: es un string que incluye el mensaje que mostrará el cuadro de mensaje.
Buttons: Define the number and type of buttons that will be displayed in the message box.
It is a numerical constant that fits the 'button table'.
Icon: Define the icon that will be displayed in the message box. It is a constant.
numeric that fits the "icon table".
Default: Set the default button in the message box. Press ENTER
it has the same effect as pressing the default button.

Constant Name Value Button


default
MB_DEFBUTTON1 0 First Button
MB_DEFBUTTON2 256 Second Button
MB_DEFBUTTON3 512 Third Button

Mode: Define the modality of the message box

Constant Name Value Description


MB_APPLMODAL 0 Application method. Stops the
current application until the
user responds to the box of
message.
MB_SYSTEMMODAL 4096 System mode. Stops all the
applications until the user
reply to the message box.

Title: It is the string that will appear in the title bar of the message box.
To know which button the user has pressed, we have the following table of values
numeric values for each type of button, which is a numeric value between 1 and 7 that returns the
MessageBox function.

Returned Value Button Constant


1 OK OK
2 Cancel IDCANCEL
3 Abort IDABORT
4 Retry IDRETRY
5 Ignore IDIGNORE
6 Yes IDYES
7 No IDNO

Activity 3

Page 14
Basic LotusScript Course

This activity produces a dialog box that asks the user for information from a
deposit and assign the value to a variable called nDeposit.
Create a button in the formxxxx in the [Link]
2. In the programming panel, enter the following code:
Dim nDeposito as Single
DepositAmount = InputBox("Enter the deposit amount")
MessageBox(nDeposit)
3. To run the script, select Design - Preview in Notes. Then click on the
button that you have created.

Activity 4

In this activity, you will use concatenation to combine string variables.


display them in a MessageBox. The ampersand (&) is used to concatenate variables
string
1. Create a button in the form xxxx in the database [Link]

2. In the programming panel, enter the following code in the button's click event:
Dim snombre as string
Dim sprofession as string

snombre = InputBox(“Ingrese su nombre: ”)


sprofesion = InputBox(“Ingrese su profesión: “)

MessageBox(snombre & " works as " & sprofesion)


3. Test the button.

Page 15
Basic LotusScript Course

7.- Variant Data, Constants and use the file [Link]

Using the Variant data type

It is a general-purpose data type. A Variant type variable can contain a


number, a string, the values of the constants NULL or EMPTY, an array, a
reference to an object or a list. When you assign a value to a Variant variable,
LotusScript determines its data type based on the value itself.

When to use Variants?

Variant type variables give the program a lot of flexibility, as the variables
they can be used differently in different operations. Use the Variants
when you are not sure about the type of data of the values that the program will manipulate.

Note: LotusScript does not have a date or time data type. Variants are
used for date and time operations.

Disadvantages of using Variants

Unless the variants are going to have a real purpose in the script, try not to
to use them for the following reasons:
Variants use more memory than other types of data.
The Variants are processed more slowly.
You can lose track of the data type of the value you are working with when
one or more variables are Variant.

Creating Constants

A constant, just like a variable, names a location in memory. While


the value of a variable can change during the execution of the program, the value of
a constant remains fixed. Use constants for values that are not susceptible to
change.
Follow these steps to create a constant:

1. Declare the constant, using the CONST statement


2. Assign the value once, and it's already declared.

Use the CONST statement with the following syntax:


CONST constant_name = value

The name of the constant can be any valid LotusScript identifier. The value
a constant is a literal that is one of the scalar data types; it can also
to be an expression that evaluates to a constant value.

Example:

Page 16
Basic LotusScript Course

The following expression creates a string constant for an address


Const DIRECCION = “Calle Barco 41”

LotusScript also brings a set of constants with predefined names that


they can be used in the scripts. These constants are defined in a file called
[Link].

Advantages of using [Link]


When the file is included in an application, you can refer to the constants.
using their names in English instead of using their numeric equivalent. For example:
the combination of the 'Yes' and 'No' buttons in the MessageBox function may refer to your
name similar to the English 'MB_YESNO' instead of its numeric value.

Syntax
To include the [Link] file in the script, write the following statement in the
module 'Globals' of the event declarations:
%Include “[Link]”

Note: If the file is located in a directory other than Notes, include the
route.

The directive %Include


This directive inserts code from another script into the current file at runtime.
compilation. Use the following syntax:
%INCLUDE "[Link]"
The directive must be the only command on a line unless a
optional comment.
The directive must be followed by a whitespace, tab character, or a
car return.
A path can be included to specify a specific directory.

Activity 5

This activity shows the use of the MessageBox function with button arguments.
and icons to obtain user information using the [Link] file.
Create a button in the formxxxx
2. In the design panel, select the 'Globals' module of the form and the event
'Declarations' to include the code

%Include “[Link]”

Page 17
Basic LotusScript Course

Fig. 6 – Include the file [Link]

3. In the click event of the button you created, include the following code:

Dim irespuesta as integer


irespuesta = MessageBox(“¿Desea continuar?”, MB_YESNO +
MB_ICONQUESTION
MessageBox(iresponse)

4. Test the button

Fig. 7 – MessageBox using [Link]

Page 18
Basic LotusScript Course

8- Creation of Comments
Creation of Comments

Comments serve as documentation for the program, to allow others


they easily understand the purpose and flow of your code.
To add comments to your LotusScript code, use any of the following
methods:
An apostrophe character ( ' ): marks the beginning of a comment in a statement.
The LotusScript compiler does not process anything that is on a line after
of the apostrophe. This can be placed anywhere on the line. The end of the line
marks the end of the comment automatically.

Example:

Dim x as integer ' Declare a variable


x = 1 ' Assign a value to x
messagebox(x) ' Displays the value

The reserved word REM: use this for comments that take up a single line.
The compiler does not process anything on a line that begins with REM.
Example:

REM The following line declares the variable x of type integer


Dim x as integer

The directives %REM and %ENDREM: use these compiler directives to


comentarios que utilizan varias líneas. %REM marca el principio del comentario y debe
appear at the beginning of a line and %ENDREM marks the end of the comment and must
be the first word in the line.

Example:

%REM
The first statement in this script declares a variable called snombre. The
The second line assigns the value 'Pablo' to snombre. The third statement displays
the value of snombre.
%ENDREM

Dim snombre as string


Snombre = “Pablo”
Messagebox(snombre)

Task 1 (Using InputBox)


Write a script in the database [Link]. A button needs to be created that calculates the
reimbursement for distance traveled. The script must do the following:
Use the InputBox function to ask the user for the number of kilometers.
2. Calculate the refund amount based on the distance traveled:
The reimbursement rate is 0.315 cents per kilometer and it is a constant value.
The reimbursement for the distance traveled is the number of kilometers multiplied by the

Page 19
Basic LotusScript Course

refund rate.
3. Mostrar el resultado del script en un cuadro de mensaje y preceder el mensaje con la
The refund is of

Page 20
Basic LotusScript Course

9- Arrays
Basic Concepts

An array is an example of a type of aggregate data. Similar to variables.


scalars, an array is declared by creating a name, specifying the data type and
assigning values. But it is distinguished from scalar variables in that a variable
array refers to multiple values instead of just one.

Array Elements

An array uses a variable name to refer to multiple values of the same type.
stored data in memory. Each value stored as part of an array is assigned
known as 'element'. The elements of the array are referenced using a
index in combination with the variable name. The index identifies an element
specific
of the array.
For example, an element in the array miArray can be referenced as miarray(1).
The following diagram represents an array with seven elements and their indices:

Fig. 8 – Array elements

Array limits

The range of indices used to specify the elements of the array is


array limits. The limits are identified by the upper and lower. Between the limits
from the array is the number of elements in the array.

The array limits are specified in the format:


lower_limit to upper_limit

Arrays have a predetermined lower bound of zero (0). Unless they are
specify the opposite, the first element of an array called myArray, will be
miArray(0).

Declaring an Array variable

The DIM statement is used to declare an array variable.

Page 21
Basic LotusScript Course

Syntax
DIM array_name(lower_limit TO upper_limit) AS data_type

Example:
To declare an array variable to store the days of the week as 7 elements
string, write the following:
Declare days(1 to 7) as String

Assignment and retrieval of values in arrays

The data of the elements of an array are assigned and retrieved in an element base.
to element. The format to assign data to an array element is:
array_name(index) = data

Activity 6

To illustrate the assignment of strings to each element of an array called myDays, make
the following:
Open the formxxxx
2. Create a button and write the following in the Click event:
Declare misDias(1 to 7) as string
misDias(1) = “Domingo”
misDias(2) = “Lunes”
misDias(3) = “Martes”
misDias(4) = “Miércoles”
misDias(5) = “Jueves”
misDias(6) = “Viernes”
misDias(7) = “Sábado”
MessageBox("The third element of misDias contains " & misDias(3))
3. Test the button

Creating dynamic arrays


You can change the stored data as elements of the array by assigning new ones.
data to the elements. The number of elements in the dimensions of the array may
change by creating a dynamic array.
Fixed arrays are declared once, their size is permanently set when they are
they declare, and reserve the memory space based on that size. The arrays
dynamic arrays are declared once but can have their size indicated multiple times
while an application is running, and therefore does not use unnecessary space.
Follow these steps to create and save memory space for a dynamic array:
1. Use the DIM statement, without specifying limits to declare the array.
2. Use the REDIM statement to set the limits and dimensions of the array once.
once it has been declared.
3. Use additional REDIM statements to indicate a new size for the array if it is
necessary.

Using the REDIM statement

Page 22
Basic LotusScript Course

Use it with the following syntax to allocate space in memory for an array:

Syntax
REDIM array_name(limits)

Example
El siguiente ejemplo muestra cómo declarar un array llamado misDias y luego
set your limits using REDIM
Dim myDays() as String
DIM myDays(1 to 7)

Changing the size of an array


Dynamic arrays can change their size many times. Every time they
Using the REDIM statement, a new upper limit can be set.

Using the PRESERVE option


Use the PRESERVE option to prevent previously existing data in the
array is overwritten.
The syntax for using the PRESERVE statement is as follows:
REDIM PRESERVE array_name(limits)

Page 23
Basic LotusScript Course

10- Conditional Sentences


These statements make decisions that result in different actions. The main
the component of these statements is a condition, which specifies the decision that is
must take. LotusScript provides two ways to perform these conditions:
IF Statements
SELECT CASE statements

IF Statements

The IF statement is used when a script needs an action when an expression is


true and another different when the expression is false. Actions are determined
based on the value of one or more expressions called conditions.

Expressions

An expression is a series of language elements that evaluate to a single value.


execution time.

Operators

Operators combine, compare, or manipulate specific values within a


expression. There are four groups of operators:

Numerical: perform arithmetic operations (+, -, *, /)

Relational: evaluates the relationship between two operands (>, <, <> and = ) When two
values are compared using these operators, the result of the expression will always be
return TRUE (1) or FALSE (0).

Logical: also known as 'booleans', are used to specify the relationship


between two quantities or concepts. The most common are NOT, AND, and OR. These
returns TRUE (-1) or FALSE (0).

They are used to manipulate string data. There are available for three types of
operations with strings:

or Concatenation (&)
Comparison (relational operations)
Pattern matching operators (Like)

Syntax
The IF ... END IF block has the following syntax:
IF condition THEN
Sentences
[ELSE
Sentences
END IF
The part that is in brackets is optional.

Page 24
Basic LotusScript Course

Activity 7

The following script checks if an account balance is greater than €300


Dim nbalance as single
Dim interest as single
nbalance = InputBox(“Ingrese el balance de la cuenta”)
if nbalance > 300 then
ninteres = 0.015
else
ninteres = 0
end if
nbalance = (ninterest * nbalance) + nbalance
MessageBox("Your balance is: " & Format(nbalance, "Currency"))

Page 25
Basic LotusScript Course

11- Select-Case Statements


These statements perform a matching operation to determine the course of
action. With SELECT CASE, the possible values to which an expression can
correspondents are listed with a corresponding action if the correspondence is
find. Use SELECT CASE when the application needs to choose between several
options.

Syntax
The following represents the syntax of the SELECT CASE statement

SELECT CASE select_expression


[CASE condition1]
[sentences]
[CASE condition2]
sentences
...
[CASE ELSE
[sentences]
END SELECT

Activity 8

The following activity uses SELECT CASE statements to perform the tests:
Sub Click(Source As Button)
Dim employeeName As String
Dim icodDept As Integer
Dim fechaCont As Variant
Dim info As Variant

snomEmpleado = InputBox(“Ingrese el nombre del empleado”)


fechaCont = InputBox(“Ingrese la fecha de contratación del empleado”)
info = employeeName & ", " & contractDate
icodDept = InputBox("Enter the department code of the employee (10, 20 or
30):")

Select Case icodDept


Case 30: Messagebox(info & ', ' & 'Marketing Dept.')
Case 20: Messagebox(info & ", " & "Sales Department")
Case 10: Messagebox(info & ", " & "Dept. of Production")
Case Else: Messagebox("Enter a valid department code (10, 20 or 30): ")
End Select
End Sub

Specifying a list of conditions or range


In addition to the individual conditions that we have already seen, a
range of conditions for a SELECT CASE statement. To specify a range:
List several specific conditions, separating them with commas. For example: CASE 10,
20, 30
Use the reserved word TO to specify a lower and an upper limit for

Page 26
Basic LotusScript Course

a range. For example: CASE 1 TO 10.


Use the reserved word IS in combination with combination operators, to
evaluate if a relational expression is true. For example: CASE IS > 10.

Activity 9

In this activity, we demonstrate the use of the reserved words TO and IS to test the
range of values:

Dim deposit as currency


ndeposito = Inputbox(“Ingrese el monto del depósito, en cientos: “)
Select Case ndeposito
Case Is < 100 : Messagebox("You have deposited less than 100€")
Case 100 to 500: Messagebox("You have deposited between 100 and 500€")
Case Is >= 1000: Messagebox("You have deposited 1000€ or more")
Case else: Messagebox("You have deposited an amount between 501 and 999€")
End Select

Using the Today() and Month() functions to build a condition


The LotusScript Month() function returns the month of the year as an integer between 1 and 12.
for any date/time argument. The Today() function returns the date of
system as a date value. By combining these two functions, it is possible to determine
the month of today's date.

Activity 10

The following shows the use of the Month() and Today() functions in a Select Case.
Dim imes as integer
Dim srespuesta as String
imes = Month(Today)
SELECT CASE imes
Case 1: srespuesta = “Enero”
Case 2: srespuesta = “Febrero”
Case 3: srespuesta = “Marzo”
... (sentences for cases 4 to 12)
END SELECT
MessageBox("We are in the month of " & srespuesta)

Tarea 2 (Utilizando SELECT CASE)


In the xxxx form, a button must be created that evaluates the current date to
determine which quarter of the year we are in.
Use the SELECT CASE statement to perform the conditional test.
Show the current quarter with a Messagebox.

Page 27
Basic LotusScript Course

12- Iteration Statements - Loops

These statements allow us to perform loops within our code, portions of


code that we want to repeat if certain conditions are met. They are very useful for
arrays and lists.

For ... Next statement


The For...Next statement is often used to store values in an array.
Syntax
FOR counter = first TO last
[sentences]
NEXT [counter]

Example
The following example shows a loop that stores values in an array
Dim i as integer
Declare family array from 1 to 7 as String

FOR i = 1 TO 5
familia(i) = Inputbox(“Ingrese los nombres de 5 miembros de su familia:”)
NEXT i

Activity 11

To demonstrate the use of the For ... Next loop, do the following:
Open the form xxxx
2. Create a button and write the following in the Click event
Dim myDays(1 to 7) as String

For i = 1 to 7
misDias(i) = Inputbox(“Ingrese los días de la semana”)
MessageBox('You just entered the day ' & misDias(i))
Next I
3. Test the button.

Task 3 (Iterative statements)


In a form, create a button labeled 'Deposit Entry' that performs the
next:
Ask the user to enter three deposits
Once the 3 deposits have been entered, show each deposit to the user with boxes of
messages.

FORALL statement
This statement repeatedly executes a block of statements for each element in a
array, list or collection. FORALL retrieves or sets all the values stored in a
array, list or collection.
The syntax is as follows:
FORALL variable_reference IN container
Sentences

Page 28
Basic LotusScript Course

END FORALL

Where
variable_referencia: es una variable de referencia para los elementos del array, lista o
collection. In the body of the Forall loop, 'variable_reference' is used to make
reference to each element of the array, list, or collection called 'container'. The
'variable_reference' cannot have a suffix character to indicate the data type.

container: it is the array, list, or collection whose elements you want to process.

Example:
To traverse all the deposits in an array called myDeposits, you could write:
For all deposits in myDeposits
MessageBox(deposits)
End Forall

Activity 12

To demonstrate the use of the Forall statements, we will create an array with values and then
we will set the entire array to 0. Do the following
1. Open the xxxx form
2. Create a button and in the Click event write the following:
Declare an array of 5 integers
array(0) = 7
array(1) = 14
array(2) = 21
For all x in array
x=0
End ForAll
3. Test the button.

DO sentence
This is an indefinite cycle because the number of times is not known in advance.
that a block of operations is executed. This type of statements are executed while
a given condition may be true or until it becomes true.

DO...LOOP statements have two different syntax forms:


DO [WHILE | UNTIL condition]
sentences
LOOP

and the other


DO
[sentences]
LOOP [WHILE | UNTIL condition]

Try before vs after


The condition for the execution of the loop is tested either before or after each one
iteration of the loop, depending on whether it is attached to the DO or the LOOP. As a result,
A DO loop that tests the condition before the loop may not execute even once.

Page 29
Basic LotusScript Course

times. For example:

Dim inum as Integer


inum = 0
DO WHILE inum < 100
inum = inum + InputBox("Enter a number")
MessageBox("The current number is " & inum)
LOOP
Messagebox("The last number was & inum)

Now an example that tests the condition after the loop is executed.
less once.

Dim inum as Integer


inum = 0
DO
inum = inum + 2
The current number is
LOOP WHILE inum < 50
Messagebox("The final number was " & inum)

WHILE ... WEND statement


This statement also executes a block of statements repeatedly while the
condition is true. LotusScript tests the condition before entering the loop and
before each repetition. The loop repeats while the condition is TRUE. When the
The condition is FALSE, the execution continues with the first statement that follows the WEND.
It is equivalent to the use of DO WHILE.

Syntax
WHILE condition
[sentences]
WEND

Example:
In this example we will set a counter, given a final number provided by the user:
Dim cont as Integer
Dim inum as Integer

inum = Inputbox("Enter a number")


i=0
While i <> inum
i=i+1
Messagebox("The number is: " & i)
Wend

Page 30
Basic LotusScript Course

13.- UI Objects of Domino Front-End

These are used to manipulate the current user interface. They are used for programming.
events and provide access to the Domino object that the user is currently working with. These
they are the most important:

Class Definition
NotesUIWorkspace Represents the current workspace window of Notes.
NotesUIDatabase It represents the database currently in use.
NotesUIView Represents the view currently used.
NotesUIDocument Represents the document that is currently open.
The following objects
they only have events
associated with them
Button It represents a button.
Field Represents a field.
Navigator Represents a guide.

Page 31
Basic LotusScript Course

14.- Back-End Objects of Domino

These objects are used to manipulate Domino data. They do not support any
event or interaction of the user interface. However, objects can be combined.
of the back-end with the front-end in UI scripts. For example, the object
'NotesUIDocument' has a property called 'Document' that gives us access to the
underlying document. These are the most important objects (not included the
related to XML)

Class Definition
NotesSession Represents the Domino environment of the current script, giving
access to environment variables, Domino directories,
information about the connected user, etc
NotesDbDirectory Represent the Domino databases on a server
specific or the workstation.
NotesDatabase Represents a Domino database.
NotesACL Represents the Access Control List (ACL) of a
database.
NotesACLEntry Represents a single entry in the Control List of
Access. An entry can be for a person, group or
server.
NotesAgent Represents an agent.
NotesView Represents a view or folder of a database and gives
access to the documents within it.
NotesViewColumn Represents a column in a view or folder.
NotesDocumentCollection Represents a collection of documents from a database
data, selected according to a specific criterion.
NotesDocument Represents a document in a database.
NotesItem Represents a piece of information in a
document (usually a field). All items in
a document is accessible through LotusScript, without
import what form is being used to display the
document in the user interface.
NotesRichTextItem Represents a rich text item.
NotesRichTextStyle Represents the attributes of the rich text field.
NotesEmbeddedObject Represents embedded objects, linked objects and
attached files.
NotesDateTime Represents a date and time. Allows performing operations.
of comparison and update between dates.
NotesDateRange Contains a range of NotesDateTime. An object of type
NotesDateTime represents a given date and time.
NotesLog Allows actions and errors to be recorded that
take place during the execution of scripts. They can
register the actions and errors in a Notes database

Page 32
Basic LotusScript Course

an email memo or a file (for the scripts that


execute locally).
NotesNewsletter It represents a document that contains information about, or
links to other documents.
NotesForm Represents a form in a Notes database.
NotesInternational This object contains properties that provide information
about international parameters, for example, format
of the date of the environment in which Domino is running.
NotesName The properties of this object contain information about
the name of a Domino user.
NotesTimer The objects represent a timer in Domino.
NotesRegistration It represents the creation or management of an ID file.
NotesOutline Represents the attributes of a Notes schema.
NotesOutlineEntry Represents an entry in a Notes schema.
NotesReplication Represent the replication parameters of a database
data.
NotesRichTextParagraphStyle Represents the attributes of the RichText paragraph.
NotesRichTextTab Represents the attributes of RichText tabulation.
NotesViewEntry Represents an entry of a view. This is a row in a
view.
NotesViewEntryCollection It represents a collection of view entries,
selected according to a specific criterion.
NotesViewNavigator It represents a view browser. This gives us access to
all or a subset of entries in a view.

Page 33
Basic LotusScript Course

15.- Hierarchy of Objects

There is a hierarchical relationship for Domino objects. The objects higher up in the hierarchy
contain those below. The following figure is an example of the hierarchical relationship between
a few Domino objects:

Fig. 2 - Hierarchy of Domino Objects

Each object has defined members, properties, and methods. Using these members,
other objects can be accessed. The content and access relationship means that the
The superior object has the property or method to access the inferior.

For example, all views can be accessed when a database is opened. This
it means that the open database (object) in the workspace includes the views
Even more, you can see the documents when you select one from the view.
This means that your selected view (object) contains the documents (object). This
Hierarchy is important when using Domino objects. NotesSession is the object in the
top of the Domino object model. Any Domino object can be accessed if
it starts from NotesSession.

Using Domino Objects with LotusScript

Now we will see an example of code that uses objects in LotusScript to understand
the movement along the route of the Domino Object Model map:

Example:
Getting the text from the Subject field

Dim ses as new NotesSession


Dim db as NotesDatabase
Dim view as NotesView
Dim doc as NotesDocument
Dim item as NotesItem

Page 34
Curso LotusScript Básico

Set db = [Link]
Set view = [Link]("Todos")
Set doc = [Link]
Set item = [Link]("Subject")

First, the variable is declared as type NotesSession, and is used to create


an instance of that object.

We declare the variables db, view, doc, item as types NotesDatabase, NotesView.
NotesDocumentNotesItem, respectively.

To obtain the text from the Subject field, we need to follow the hierarchical path from the
top to the lowest. In this example, we go from NotesSession to NotesItem.

We initialized the variable db with the CurrentDatabase property of the level object.
superior.

We initialize the variable view using the GetView method, naming the view.

The following statements are the same as the above: we use the methods
GetFirstDocument to obtain the first document from the view and GetFirstItem to
obtain the Subject field of the document.

Understanding Front-end and Back-end classes

First, you need to consider how information is stored in Domino. You can think
that a document within a Domino database is a record, but a
Domino document is more sophisticated than a typical database record.
It may contain rich text, images, objects, and other types of information.
For example, if you access a Domino document using the back-end classes, you can
manipulate the content of the fields, add new fields to the document, or delete
fields of the document. However, if you make such changes, the translation formulas
and the validations that exist in the form will not be executed.

On the other hand, if you work with front-end objects, your changes to the fields are
visible to the user. For example, if you invoke the Refresh method of the class
NotesUIDocument, the translation and validation formulas will be executed.

The following figure represents a document in the back-end and shows how the data
are stored in a Domino database:

Page 35
Basic LotusScript Course

Fig. 3 - Data stored in a Domino database

The fields Field1 and Field2 have been designed in the form that was used to
create this document. The name of this form is stored in the fieldForm. If
you change the value of the field form using an agent or with LotusScript, the document is
will present the user using the other form when it is opened next time.

Observation: If there is no field in a document, Domino will show this document.


using the default database form. If there is no form
default, the document cannot be displayed.

The field $UpdatedBy is an internal field created by Domino and contains a list of the
users who have worked with this document.

Observation: Mostly, the fields that start with $ are used and maintained by Domino.

Page 36
Basic LotusScript Course

a range. For example: CASE 1 TO 10.


Use the reserved word IS in combination with combination operators, to
evaluate if a relational expression is true. For example: CASE IS > 10.

Activity 9

In this activity, we demonstrate the use of the reserved words TO and IS to test the
range of values:

Dim deposit as currency


ndeposito = Inputbox(“Ingrese el monto del depósito, en cientos: “)
Select Case ndeposito
Case Is < 100 : Messagebox("You have deposited less than 100€")
Case 100 to 500: Messagebox("You have deposited between 100 and 500€")
Case Is >= 1000: Messagebox("You have deposited 1000€ or more")
Case else: Messagebox("You have deposited an amount between 501 and 999€")
End Select

Using the Today() and Month() functions to build a condition


The LotusScript Month() function returns the month of the year as an integer between 1 and 12.
for any date/time argument. The Today() function returns the date of
system as a date value. By combining these two functions, it is possible to determine
the month of today's date.

Activity 10

The following shows the use of the Month() and Today() functions in a Select Case.
Dim imes as integer
Dim srespuesta as String
imes = Month(Today)
SELECT CASE imes
Case 1: srespuesta = “Enero”
Case 2: srespuesta = “Febrero”
Case 3: srespuesta = “Marzo”
... (sentences for cases 4 to 12)
END SELECT
MessageBox("We are in the month of " & srespuesta)

Tarea 2 (Utilizando SELECT CASE)


In the xxxx form, a button must be created that evaluates the current date to
determine which quarter of the year we are in.
Use the SELECT CASE statement to perform the conditional test.
Show the current quarter with a Messagebox.

Page 27
Basic LotusScript Course

b) Instantiate the back-end object directly through the getView method


belonging to the class notesdatabase:

Set view=[Link]("Clients") (where bd is the database that


contains the view we are looking for and 'Clients' is the name or alias of the
view that we wish to instantiate

The NotesView object is one of the most important in Domino because through it
we can access the system documents that ultimately contain
all the information of an application. Therefore, we will see how to navigate through the
documents of a view.

To do this, there are two methods in the NotesView class, which are:

a) Set doc = [Link]() --- where doc is a NotesDocument object


(as it will be seen in the next section) and view is a notesView object. With
In this method, we obtain the first document from a view with a view to go
traversing this sequentially
b) Set docSig = [Link](doc) --- where docSig is the object
NotesDocument that we want to obtain, doc is the current NotesDocument object
and view is a notesView object. With this method, we obtain the following
document a doc(docSig) according to the order of the view

The NotesView object has a large number of properties and methods. For a
Complete description of them, access the Domino Designer help.

NotesDocument object: Represents a document in the Notes database. It is the


main unit of information in the Notes/Domino environment.
Documents are usually created by a user action, although they can also
They can be created from code. The Form field of the document will contain the name.
from the form with which it was created.

There are several ways to instantiate a document:

a) Create it from the code itself:

Set doc=New NotesDocument(bd) where bd is the object that represents the database
of physical data where the new document created will be stored

b) Retrieve it from a view

Set doc=[Link]()
Set docSig=[Link](doc)

c) Retrieve it from a collection of documents

Set doc=[Link]()

Page 38
Basic LotusScript Course

Set docSig=[Link](doc)

In this case, they work the same as when retrieving them from a view. One obtains the
first document and then the rest are obtained sequentially,
starting from the previous one.

Set docAny=[Link](pos)

With the previous instruction, we retrieved a document that is located in the


position indicated bypos within the order defined by the collection.

Other actions to be taken with documents:

a) Save

Call [Link](a,b)

The action requires two boolean parameters. (Possible values: true or false)

El primero nos pregunta si el documento se guardará aunque esté editado por


another user at that time. If true is indicated, the document will be saved, if
indicate false, it will not be saved.

The second parameter depends on the first. If a is true, the value of b is


ignored (does not mean that it can be omitted). In case a is false, it
it will produce the following situation:

If b=true, the document will be saved as a replication conflict.


If b=false the document will not be saved

b) Delete

Call [Link](a)

The action requires a boolean parameter. (Possible values: true or false)

The parameter will decide whether the document will be deleted even if it has been edited by another.
user at that moment. If true is indicated, the document will be deleted, if indicated
false it will not be saved.

c) Send

Call [Link](a)

The action requires a boolean parameter. (Possible values: true or false)

The parameter will decide whether the document being sent will include a
form for your viewing. If true is indicated, the document will carry it, if
indicates false it will not take.

Page 39
Basic LotusScript Course

To access the contents of the document (the fields), we must take into account the following
next

a) The system treats the fields of a document as an array of multiples


values.
b) The first position of that array is always 0
c) To refer to the content of a field with a single value we will have
to use the following notation:

Client=[Link](0) This statement loads the content into the variable client
from the field Name that is in the document doc

The NotesDocument object has a large number of properties and methods. For a
complete description of them access the Domino Designer help.

NotesDateTime object: Represents a date

Actions to be taken with date objects:

Creation

To create a new NotesDateTime object, you must use the following syntax:

Set newDate= New NotesDatetime(datePattern)

Where patronDate is a string, a date, or any pattern that the system


recognize as a valid date

Modification

To modify a NotesDateTime object we will use the following methods of the


same.

-Call [Link](n) - Where n must be an integer. If n is


positive newDate is advanced by the number of days indicated by n. If n is
negative newDate is delayed by the number of days indicated by n.

-Call [Link](n)–Where n must be an integer. If n is


positive newDate is advanced by the number of months indicated by n. If n is
negative newDate is delayed by the number of months specified by n.

-Call [Link](n)–Where n must be an integer. If n is


positive newDate advances by the number of years indicated by n. If n is
negative newDate is delayed by the number of years indicated by n.

Existen métodos similares para modificar la parte horaria del objeto nuevaFecha.
Consult the Domino Designer help for more information about
they.

Page 40
Basic LotusScript Course

c) Comparison between dates

To compare two dates, the TimeDifference method associated with one of them is used.
them. For example, to compare two date objects, date1 and date2, the syntax
it would be the following:

Difference = [Link](date2)

The execution of this statement returns the difference in seconds that exists
between date1 and date2.
In this case, if date1 is less than date2, the difference will have a negative value.
whereas if it is the other way around, the difference will have a positive value.
If the two dates were identical, the result would be 0.

d) Obtain only the date part

To obtain the date part we will use the following syntax:

OnlyDate=[Link]--The result returned and stored in


soloFecha es un string

e) Obtain only the hourly part

To obtain the hourly part we will use the following syntax:

SoloHour=[Link]--The result returned and stored in


soloFecha is a string

The object NotesDateTime has a large number of properties and methods. For a
complete description of them access the Domino Designer help.

NotesUIWorkspace: This is a UI-End object and represents the environment of


work in which the Domino session is being developed.

To instantiate an object of this type we must use the following syntax:

Dim wk as new notesuivorkspace

The NotesUIWorkspace object will be very useful to us when we want to work with the
information we have on screen at any moment

The most important actions to be developed with this object are:

a) Obtain the current document

Set uidoc=[Link]--In uidoc we have the document on screen

Page 41
Basic LotusScript Course

Set doc=[Link]–In doc we have the back-end document to which


represents the uidoc

b) Create a new document based on a form and display it

Set uidoc=[Link]([ server$ [,file$ [,form$ [,windowWidth# [,


windowHeight# ]]]]] )

c) Edit or show a back-end document

Set uidoc= wk,EditDocument([editMode [, notesDocument [,


notesDocumentReadOnly [, documentanchor$ ]]]])

d) Update the current view on screen

Call [Link]

The object NotesUIWorkspace has a large number of properties and methods.


a complete description of them access the Domino Designer help.

Object NotesUIDocument: This is a UI-End object and represents the document


active in the session I dominate

To see how to create, edit, or display a UI-End document, review the object
anterior NotesUIWorkspace.

To access the values of a field from a notesUIDocument object we will use the
next syntax:

Value=[Link]("Name")–The value stores what it contains


field Name in string format

To modify the values of a field from a notesUIDocument object we will use the
next syntax:

Call [Link](fieldName, newValue) – Where fieldName is the


field that you want to modify (must be in quotes) and newValue is the value
what will be assigned to that field (it should also be in quotes)

El objetoNotesUIDocumenttiene un gran número de propiedades y métodos. Para una


Complete description of them access the Domino Designer help.

Page 42

You might also like