Home > Domino Tips > Developer > LotusScript > Auto-generate LotusScript setter and getter properties for class variables
Domino Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

LOTUSSCRIPT

Auto-generate LotusScript setter and getter properties for class variables


Mike Brown
10.02.2007
Rating: -3.25- (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


Related resources from SearchDomino.com:
Tutorial: 30 LotusScript tips

FAQ: LotusScript

LotusScript Learning Guide

LotusScript Reference Center

Here's the problem. You're using object-oriented LotusScript to create classes and objects. Like a good object-oriented LotusScript developer, you're declaring all your class variables as "Private" and then writing "Setter" and "Getter" properties to allow access to them.

The truth is, most of the "Setter" and "Getter" properties that you would write offer direct read/write access to those variables anyway -- and writing them out is such a pain! You could cheat and declare the class variables as public or you could have a Lotus Notes form generate them for you.

Here is the code for a button that will do just this:

private m_MyVar1 as string
private m_MyVar2 as Variant
private m_MyVar3 as Integer
private m_MyVar4() as string

That will generate these:

Public Property Get MyVar1 as String
MyVar1 = me.m_MyVar1
End Property
Public Property Set MyVar1 as String
me.m_MyVar1 = MyVar1
End Property
Public Property Get MyVar2 as Variant
MyVar2 = me.m_MyVar2
End Property
Public Property Set MyVar2 as Variant
me.m_MyVar2 = MyVar2
End Property

... and so on.

To further set this up, create a Lotus Notes form in any Lotus Notes database and put two text fields in it.

These text fields should be labeled as:

  • Input: This is a multi-value Lotus Notes text field. Set the multi-value options tick boxes to use "NewLine" for both display and input.
  • Output: This is a single value Lotus Notes text field.

Now follow these steps:

  1. Create a button on the form and paste the button code below into its LotusScript Click event.
  2. Create a new Lotus Notes document from the form and paste your class variable declarations into the Input field.
  3. Click the button.

The "Setter" and "Getter" properties will be created in the Output field. You can then copy and paste the LotusScript below into your class definition code:

Button code
Dim session As New NotesSession
Dim ws As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Dim doc As NotesDocument
Dim inputVar As Variant

Set uidoc = ws.CurrentDocument
Set doc = uidoc.document

Call doc.ComputeWithForm
(False, False)

inputVar = doc.Input
If inputVar(0) = "" Then
Messagebox "No input found"
Exit Sub
End If


%REM
Assumptions are that class variables 
will declared thus private m_MyVar1 as 
string private m_MyVar2 as Variant private 
m_MyVar3 as Integer private m_MyVar4() 
as string

and so on. We use the Split function to 
create a variant array (tempVar) of 4 members. 
These will be
tempVar(0) = the word "Private".
tempVar(1) = the variable's name
tempVar(2) = the word "as"
tempvar(3) = the variable's type.

You need two text fields on a form:
"Input" = multi-value Text field. Set the multi-value 
options tickboxes to use NewLine.
"Output" = single value Text field
%END REM
Dim outputString As String
Dim tempString As String
Dim tempVar As Variant
Dim variableName As String
Dim setgetVariableName As String
Dim variableType As String
Dim NL As String
outputString$ = ""
Dim classVariablePrefix As String
classVariablePrefix$ = "m_"
NL$ = Chr$(13) & Chr$(10) ' True for 
Windoze only. Should change for Mac or 
Linux clients.
Forall inputLine In inputVar
tempVar = Split(inputLine, " ")
variableName = Trim(tempVar(1))
variableType = Trim(tempVar(3))

If Instr(variableName, "(") > 0 Then ' must be 
an array, so need to declare the set and 
get as Variant variableName$ = 
Strleft(variableName$, "(") variableType$ = 
"Variant"
End If

If Instr(variableName$, classVariablePrefix$) > 0 
Then setgetVariableName$ = Strrightback
(variableName$, classVariablePrefix$) Else 
setgetVariableName$ = variableName$ End 
If outputString$ = outputString$ & "public 
property get " & setgetVariableName$ & " as " 
& variableType$ & NL$ outputString$ = outputString$ 
& Chr$(9) & setgetVariableName$ & " = me." 
& variableName$ & NL$ outputString$ = 
outputString$ & "End Property" & NL$ outputString$ = 
outputString$ & "public property set " 
& setgetVariableName$ & " as " & variableType$ 
& NL$ outputString$ = outputString$ & Chr$(9) 
& " me." & variableName$ & " = " & setgetVariableName$ 
& NL$ outputString$ = outputString$ & "End Property" 
& NL$ & NL$ End Forall

doc.Output = outputString
Call uidoc.reload 

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

This tip was submitted to the SearchDomino.com tip library by member Mike Brown. 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.




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



RELATED CONTENT
LotusScript
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
LotusScript agent automates selective mail file replication

LotusScript
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 filters and attaches files to a Notes form

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