Welcome to

The Conxsys Blog

Thoughts on Conxsys, Notes/Domino, LotusScript, & Technology

SnTT: Using Me to Create Class Members with Reserved Keywords

January 3rd, 2008 by Corey Davis

Notes 8 LogoWe all know that we can use the keyword Me to refer to class variables from within the class methods and properties. (If you are not creating your own classes you should be! They are a fantastic way to create reusable, fully unit-tested code.) But, did you know that you can use it to refer to methods and properties? Based on the amount of code I read last year that did not seem to understand this concept I am assuming that some of you possibly do not know about this or just plain forgot. Why is this even important? Because it allows you to use LotusScript reserved keywords as names for your methods and properties. And that is important because in many cases it will make for more developer-friendly code. Here’s why:

Let’s assume that you are creating a specialized wrapper class for the NotesDocument class (don’t even get me started on the inability for developers to sub-class the standard base classes!). You have decided that one of the methods you would like to include is Close because, well, it just makes so much sense. And Close should return a Boolean result based on whether or not the method completed successfully. The problem is that Close is a reserved LotusScript keyword so you can’t use it the way you want to:

Public Function Close As Boolean
	Close = m_doc.Save(True, False)
	Set m_doc = Nothing
End Function

This LotusScript was converted to HTML using the ls2html routine,
provided by Julian Robichaux at nsftools.com.

You will not be able to save this code because you will receive this error in reference to the second line of code:        Unexpected =; Expected: Expression; End-of-statement; #

And this makes sense because, after all, Close is a reserved keyword. You cannot assign a Boolean value to Close because LotusScript expects it to be used to close a file as in:

Close #1

This is the point were many developers raise their hands in frustration and end up renaming their methods to CloseDoc or SaveAndClose or something along those lines. And while there is nothing wrong with these choices from a technical view point, and they are descriptive in nature to their function, it is easy to forget the method’s name when coding. When it comes to class development it is the developers that are your end-users and using all sorts of different, non-standard method names just makes life that much more difficult.

In order to allow us to use the method above and send back a Boolean value, we simply need to use the Me keyword:

Public Function Close As Boolean
	Me.Close = m_doc.Save(True, False)
	Set m_doc = Nothing
End Function

This LotusScript was converted to HTML using the ls2html routine,
provided by Julian Robichaux at nsftools.com.

This informs the compiler that you are referring to the current class’ Close method and not the reserved Close keyword. You can also use it in other functions to call the Close method as in:

Public Sub Delete
	If Not(m_doc Is Nothing) Then Call Me.Close
End Sub

 

This LotusScript was converted to HTML using the ls2html routine,
provided by Julian Robichaux at nsftools.com.

Using the Me keyword in this fashion is documented in the Designer Help, but sparsely so don’t feel too bad if you missed it. Below is the LSS file for the example code used above. It includes a class called MyDocument in the Declarations section as well as some code that uses the class in Initialize. Play around with it by removing the Me keyword in the Delete and Close methods to see how it stops working.

Me Keyword Example Code


Tags: , , , , ,
Posted in SnTT, 1,274 views, 0 Comments
Digg This Submit to del.icio.us Submit to Technorati  

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.

CC-GNU GPL Creative Commons License
The Conxsys Blog by Corey Davis is licensed under a Creative Commons Attribution 3.0 Unported License unless otherwise specified. Based on a work at conxsys.com/blog. All code on this blog is licensed under the CC-GNU GPL version 2.0 or later unless otherwise specified.


Copyright © 2006-2010 by Conxsys | Login | Powered by Wordpress | Template based on a design by Design4