logo

Still Learning LotusScript - The DataType Fuinction

In trying to solve a problem with some code I inherited I stumbled upon the DataType function of LotusScript, which I'd never used before.

My code was calling a function and expecting a List of Strings back. Like so:

Dim aList as Variant
aList = MakeMeAList()
Msgbox aList("Foo2")

The function which built this list of strings looked something like:

Function MakeMeAList() as Variant
 Dim theList List As String
 theList("Foo1") = "bar1"
 theList("Foo2") = "bar2"
 MakeMeAList = theList
End Function

Obviously the code was a bit more complicated than that. What it actually did was look for a profile for a supplied username and then return details of the user. If a profile couldn't be found it just added an item to the List called "Error".

The trouble with the code was that this error approach didn't seem to work and I just kept on getting "variant doesn't contain a container". The only way I found by which I could safely test whether I'd got a List back was using this new-found DataType function, as below:

Dim aList as Variant
aList = MakeMeAList()
If DataType(aList)=2056 Then 'Variant(2048) + String(8) = 2056
 Messagebox aList("Foo2")
Else
 Messagebox "That ain't no list of strings fool!"
End If

You live and learn. Although whether learning new LotusScript techniques at this point in the game is of any use is likely to be debatable.

Comments

    • avatar
    • Flaz
    • Wed 30 Jun 2010 05:41 AM

    (Take a look at the title! :P)

      • avatar
      • Kerr Rainey
      • Wed 30 Jun 2010 08:56 AM

      I think you might need to be more explicit.

      *cough*typo*cough*

    • avatar
    • Niel Revelle
    • Wed 30 Jun 2010 07:25 AM

    Thanks for the tip, didn't realize you could test for what datatype the list is. I've always just used IsList to see if a variant function did return a list as expected.

      • avatar
      • Jake Howlett
      • Wed 30 Jun 2010 07:34 AM

      Doh, IsList() might have been easier. If I'd remembered its existence that is...

  1. I'm surprised you don't use Java.

    Maybe it's my background but I've always interfered Java to LotusScript. The only times I used LotusScript was when I had to make my code work in the Notes Client.

    1. Oh, you inherited the code ... that's the other times I've used LotusScript. Although in a few cases I just reimplemented the functionality in Java.

      • avatar
      • Jake Howlett
      • Wed 30 Jun 2010 03:07 PM

      I've always preferred LotusScript. You just know where you are with it. I've never really trusted Java in Notes. I know that's crazy but I can't shake the feeling and only use Java when LotusScript can't cut it.

      Show the rest of this thread

  2. This is way off-topic ... sorry ... but I just had to share this link to a Lotus Notes consulting firm:

    http://www.sr-sys.com/data/webs/sr-sys/sr-sys.nsf

    Then be sure to notice that, in addition to offering Lotus Notes hosting, they sell Rock & Lapidary equipment.

    So clearly they aren't getting enough Notes business and, instead of branching out into SharePoint and .Net, they've taken a different route to bolster their cash-flow.

    Sorry, sorry, but I just had to share this with someone who would understand the irony.

    Peace,

    Rob:-]

      • avatar
      • Jake Howlett
      • Wed 30 Jun 2010 03:00 PM

      What on earth is Lapidary though?

      Show the rest of this thread

  3. There are a few Is* functions to test what a variant contains.

    - IsList - as already mentioned.

    - IsArray.

    - IsObject.

    IsList and IsArray don't care about the data type of each element of the list/array, so the DataType function is still useful in this case.

    Also, to get named constants for the return value of DataType: %include "lsconst.lss", or use the TypeName function instead.

Your Comments

Name:
E-mail:
(optional)
Website:
(optional)
Comment:


About This Page

Written by Jake Howlett on Wed 30 Jun 2010

Share This Page

# ( ) '

Comments

The most recent comments added:

Skip to the comments or add your own.

You can subscribe to an individual RSS feed of comments on this entry.

Let's Get Social


About This Website

CodeStore is all about web development. Concentrating on Lotus Domino, ASP.NET, Flex, SharePoint and all things internet.

Your host is Jake Howlett who runs his own web development company called Rockall Design and is always on the lookout for new and interesting work to do.

You can find me on Twitter and on Linked In.

Read more about this site »

More Content