LOTUSSCRIPT LANGUAGE


Interacting with the user
Lotus products lend themselves to building interactive applications, applications that incorporate user input and prompt the user to perform particular tasks. While each individual Lotus software application provides its own user interface for interacting with scripts, LotusScript supplies some fundamental tools that you can use with any Lotus software.
This example uses the InputBox function to get monthly revenue and expenses from the user, converting strings to Currency.

The script computes the balance, then uses a MessageBox statement to display the balance, formatted as Currency.

Sub CalcBalance
  Dim revenue As Currency, expenses As Currency, balance _
    As Currency
  revenue@ = CCur(InputBox("How much did we make" & _
   " this month?"))
  expenses@ = CCur(InputBox("How much did we spend?"))
  balance@ = revenue@ - expenses@
  MessageBox "Our balance this month is " _
     & Format(balance@, "Currency")
End Sub

The two input boxes with sample entries and the resulting message box are:

Three message boxes, two that collect user input and a third that displays the result of a calculation

If the user enters a string that the CCur function cannot convert to Currency, an error condition occurs. You can use an On Error statement to branch to an error-handling routine in such a case.

This expanded version of the example uses the MessageBox function to ask the user whether to try again. The second message box also contains a question mark icon, specified by MB_ICONQUESTION (32). To use constants rather than the numbers to which they correspond as MessageBox arguments, you must include the file that defines these constants, LSCONST.LSS, in the module declarations.

%Include "LSCONST"

Sub CalcBalance
  Dim revenue As Currency, expenses As Currency, balance _
    As Currency
  EnterValues:
  On Error GoTo BadCur:
  revenue@ = CCur(InputBox("How much did we make" & _
   " this month?"))
  expenses@ = CCur(InputBox("How much did we spend?"))
  balance@ = revenue@ - expenses@
  MessageBox "Our balance this month is " _
     & Format(balance@, "Currency")
  Exit Sub

   BadCur:
  If MessageBox("Invalid entry! Do you want to try again?", _
     MB_YESNO + MB_ICONQUESTION) = IDYES Then GoTo _
     EnterValues
  Exit Sub
End Sub

When the user enters an invalid entry, the message box offers the option of making another entry:

For more information about error processing, see the chapter "Error Processing."

MsgBox on Notes server context

When you run LotusScript agents on the Notes server, the commands MsgBox, Inputbox, and Print will be re-directed to the status bar and will be put into the agents log.

For HTTP servers, these commands redirect the output to the browser. You can create HTML pages dynamically using these commands to serve to any browser.

See Also