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.
(Take a look at the title! :P)
Reply
I think you might need to be more explicit.
*cough*typo*cough*
Reply
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.
Reply
Doh, IsList() might have been easier. If I'd remembered its existence that is...
Reply
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.
Reply
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.
Reply
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.
Reply
Show the rest of this thread
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:-]
Reply
What on earth is Lapidary though?
Reply
Show the rest of this thread
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.
Reply