Easily save and load Lotus Notes user preferences using a UDT

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
    glUDT.name = "The Current User"
    glUDT.id = 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 glUDT.name & " 
    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 SearchDomino.com 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.

This was first published in June 2006

There are Comments. Add yours.

TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.