Home > Domino Tips > Developer > LotusScript > Easily save and load Lotus Notes user preferences using a UDT
Domino Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

LOTUSSCRIPT

Easily save and load Lotus Notes user preferences using a UDT


Joe Steblay
06.20.2006
Rating: -3.30- (out of 5)


Lotus Notes and Domino tips, tutorials and how-to articles
Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google


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:
    (Declarations)
    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.

Rate this Tip
To rate tips, you must be a member of SearchDomino.com.
Register now to start rating these tips. Log in if you are already a member.


Submit a Tip




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google



RELATED CONTENT
LotusScript
LotusScript agent parses ACL to Microsoft Notepad
LotusScript finds the first occurrence of a string from the right
Clear Recent Contacts view and prevent repopulation in Lotus Notes 8.x
Search Microsoft Active Directory with LotusScript
Three steps to trap and handle save conflicts with LotusScript
Troubleshoot agents by displaying LotusScript variables online
LotusScript sorts lists alphabetically
LotusScript code rebuilds corrupted busytime.nsf file
Soft-code item names to facilitate LotusScript management
LotusScript agent automates selective mail file replication

LotusScript
LotusScript agent parses ACL to Microsoft Notepad
LotusScript finds the first occurrence of a string from the right
Clear Recent Contacts view and prevent repopulation in Lotus Notes 8.x
Search Microsoft Active Directory with LotusScript
Three steps to trap and handle save conflicts with LotusScript
Troubleshoot agents by displaying LotusScript variables online
LotusScript sorts lists alphabetically
Run or restart Notes/Domino agents via text messages
LotusScript code rebuilds corrupted busytime.nsf file
Soft-code item names to facilitate LotusScript management

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

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.



Domino & Lotus Notes Security Solutions: Authentication, Antispam, Encryption and Antivirus
HomeTopicsITKnowledge ExchangeTipsAsk the ExpertsMultimediaWhite PapersDomino IT Downloads
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 1999 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts