Manage Learn to apply best practices and optimize your operations.

Easily save and load Lotus Notes user preferences using a UDT member Joe Steblay provides step-by-step instructions on how to use a User Defined Type to save Lotus Notes user data or preferences. This technique works particularly well for saving a lot of global variables or user-defined object states, since you can save a lot of data locally using very little code.

This technique can be used to easily save user-specific data or preferences. It is similar to using profile documents, however, you don't need to use explicit variable names when writing or reading the data.

Instead, set up a User Defined Type (UDT) with the variables, and then just read/write the UDT as a binary file. The nice thing about this is that you don't need to modify the methods that would read/write the data as you add variables to your UDT.

This works great for saving a lot of global variables and saving user-defined object states (on/off). You can save a lot of data locally with very little code. Typically, some of the code would exist in different methods but have been chunked together here to keep things simple.

  1. Set up a LotusScript library to hold the UDT. I created a LotusScript Library called "Utilities" with a small UDT in the declarations section. This example creates "count", "name", and "ID" variables in the UDT.

  2. Add the following code to the "Declarations" section of the library:
    Public Type myUDT
     count As Integer
     name As String
     id As Integer 
    End Type
  3. Create a form.

  4. In the "Globals" section of the form, select the "Options" section and add this line of code so that the LotusScript Library can be used:
    Use "Utilities" or whatever you called 
    your LotusScript library that has the UDT.
  5. In the "Globals" section of the form, select "Declarations" and add the following code. This declares a new UDT called "glUDT" that can be used by the form.
    Dim glUDT As myUDT
  6. In the "Globals" section of the form, select the "Initialize" section and add the following code. This will read the UDT variables when the form is opened and set all of the variables with the data read from the file automatically! The file used in this example is "c:testUDT.txt"
    Dim filenum As Integer 
    Dim filePath As String 
    filenum = Freefile 
    filePath = "c:testUDT.txt"
    'check to make sure file exists 
    (it won't run the first time)
    If Dir(filepath) <> "" Then
     Open filePath For Binary As filenum
     Get filenum , , glUDT
     Close filenum
     End If
  7. Add a button to the form with the following code in the LotusScript "Click" event. This code sets the variables in the UDT every time it is clicked (you can change the name if you want to). Note that the "count" variable is increased by one every time the button is clicked so that you can see it work. The code saves the UDT (with the variables) to a binary file, and then pops up a message with the current count.
    'set the UDT variables = "The Current User" = 123
    glUDT.count = glUDT.count + 1
    'write the variable to a binary file
    Dim filenum As Integer 
    filenum = Freefile
    Open "c:testUDT.txt" For Binary As filenum
    Put filenum , , glUDT
    Close filenum
    'display the current count
    Msgbox & " 
    has set this [ " & glUDT.count & " ] times."
  8. Open the form in the Lotus Notes client and click the button a few times. The count should increase by one with every click.

  9. Close the form, reopen it, and click the button again. The count should keep increasing from where you left off before you closed it.

This is a quick and easy way to save data locally and has several different uses.

Do you have comments on this tip? Let us know.

This tip was submitted to the tip library by member Joe Steblay. Please let others know how useful it is via the rating scale below. Do you have a useful Lotus Notes, Domino, Workplace or WebSphere tip or code snippet to share? Submit it to our monthly tip contest and you could win a prize.

Dig Deeper on LotusScript

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.




  • iSeries tutorials's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...