Friday, April 20, 2012

Overloading functions in Lotusscript

At times I find it difficult with out the ability to over load functions in lotusscript. The following way just helped me do it. Since I dont do this often its like new to me every time I do this :)

Sub new(key As Variant)
     Select Case Typename(key)
     Case "STRING":
           your code for this type
     Case "INTEGER"

          your code for this type
     Case "NOTESDOCUMENT"
          your code for this type
     Case Else
         your code for this
End Select
We have to be wary about the usage of such functions though. One stuff that I found was Typename(Nothing) is object. I least expected that.

I dont think using overloaded functions in lotusscript is a time saver. As a matter of fact I found this and just dropped the idea of using it after trying to use it :P. Cos man..., it was a head ache to me. I couldn't have a dynamic parameter list like how we can do in javascript and definetly can't match the way we do it in java or C or C++ anyway.

So I felt crippled when using this idea. However, this must help in some scenarios. Hope you find this in one such case :)

2 comments:

  1. I actually use that method, not only in the class constructor, but also in some methods. For example, many of my methods takes a date argument. So what I do is to check if the argument is a string or a date object, and if it is a date object I get the date as a string aout of it.
    This way I can call the method with different data types.

    ReplyDelete
  2. I get it. That a really nice comment. Thanks for that

    ReplyDelete