OpenNTF.org - Auto-generate Setters and Gett
    Advanced
   OpenNTF Code Bin
Edit Document Code By Date > Code Document
About This Code
Brief Description:
Auto-generate Setters and Getters for LS Class Variables 
Rating:
Not Rated Yet 
Contributor:
Mike Brown 
Category:
Lotusscript 
Type:
Example Code 
Notes Version:
R6.x, R7.x 
Last Modified:
10 Jun 2007 
OpenNTF Disclaimer

All of the program code and information presented in the OpenNTF.org Code Bin are provided "as-is", and should be used at your own risk. OpenNTF.org make no express or implied warranty about anything in the Code Bin, and OpenNTF.org will not be responsible or liable for any damage caused by the use or misuse of anything from this site. OpenNTF.org makes no guarantees about anything. Please thoroughly test all of the knowledge and code you find here before you attempt to use them in your production environment.

Code / Description
Here's the problem. You're using object-oriented LotusScript to create Classes and Objects. Like a good OO boy/girl, you're declaring all your Class variables as Private and then writing Setters and Getter Properties to allow access to them. Truth is though, most of the Setters and Getters that you write simply offer direct read/write access to those variables anyway, and writing them all out is such a pain! You could cheat and declare the class variables as public (go sit in the corner and put that "D" hat on), or you could have a Notes form generate them for you.


Below is the code for a button that will take this:
private m_MyVar1 as string
private m_MyVar2 as Variant
private m_MyVar3 as Integer
private m_MyVar4() as string

and 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 set this up, create a Notes form in any database and put two Text fields on it. These should be:
"Input" = multi-value Text field. Set the multi-value options tickboxes to use NewLine for both display and input.
"Output" = single value Text field

Create a button on the form and paste the Button code below into it's LS Click event. Create a new document from the form and paste your Class variable declarations into the Input field. Click the button. The Setters and Getters will be created in the Output field. You can then copy and paste these into your Class definition code.

Cheers,

- Mike


' ***********************************************************8
' 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
' ***********************************************

Usage / Example
 Comments

No documents found

 Add your comment!