LotusScript: Using Lists to Help Export Domino Names To Exchange
The other day I mentioned Lists in LotusScript. By coincidence yesterday I found myself using them again.
As part of helping a customer migrate from Domino to Exchange I've written them an agent to export all people from their NAB in to a CSV file, which will then be imported to Exchange's address book.
For reasons I'm not entirely clear on they needed an extra column adding to the CSV called "Initial". For most people this would simply be "1". If the export found a name that had already exported for another user then the "Initial" column needed to increment to 2 - even though there was a "unique ID" column in the CSV - and so on.
So the CSV would look like (ignoring lots of missing columns):
First Name, Last Name, Initial Jake, Howlett, 1 John, Smith, 1 Karen, Howlett, 1 John, Smith, 2 Joe, Taylor, 1 John, Smith, 3 Karen, Howlett, 2
You get the idea, right?
It turned out doing this was really simple in LotusScript using Lists. Here's how:
Dim NameCount List As Integer Dim NameFull As String 'this bit inside a loop of all Person documents (doc) NameFull=LCase(Trim(doc.FirstName(0))+" "+Trim(doc.LastName(0))) If IsElement(NameCount(NameFull)) Then NameCount(NameFull)=NameCount(NameFull)+1 Else NameCount(NameFull)=1 End If Print #fileNum%, doc.FirstName(0)+{,}+doc.LastName(0)+{,}+ CStr(NameCount(NameFull))
In fact it turns out you can simplify that code even further to:
Dim NameCount List As Integer Dim NameFull As String 'this bit inside a loop of all Person documents (doc) NameFull=LCase(Trim(doc.FirstName(0))+" "+Trim(doc.LastName(0))) NameCount(NameFull)=NameCount(NameFull)+1 Print #fileNum%, doc.FirstName(0)+{,}+doc.LastName(0)+{,}+ CStr(NameCount(NameFull))
There you go. LotusScript still standing the test of time...
You sure that would work? I'm pretty sure that reading a listitem that does not exist yet causes an error. That is, I would always code the first example
Reply
I know. Seems strange doesn't it. This is the behaviour you'd expect of JavaScript or some such. You'd expect LotusScript to throw a wobbly over that, but it does work.
Reply
Show the rest of this thread
just missing the
If Not IsElement(NameCount(NameFull)) Then NameCount(NameFull)=0
after setting the NameFull
Reply