About Me...

NotesRunningLogoRSmall.png

I'm Kathy Brown and I've been an application developer in Lotus Notes/Domino since 2005.

Prior to working in IT, I've had numerous careers including an Investment Analyst and even an Actress (long ago and far away).

And I (try to) love running!

me.jpg

kathy (at) runningnotes (dot) net

On Twitter, kjbrown13

Upcoming Races

Looking 4 Something?

Disclaimer

This is my personal blog. None of the opinions shown here represent those of my employer. In fact, forget I even have an employer. Any examples given here are strictly fictional and hypothetical and it is pure coincidence if they in any way seem like anything in real life.

« Saunders 10k Race Report - Updated | Main| Lotus Marketing and Alternate Universes »

Fun with Lists!

Category Lotus Notes Newbies Development Lists
Lotusscript lists, that is. Frequently underutilized by developers (including me), but a very useful tool nonetheless. I had a need recently to loop through some documents, and create a unique list of names from those documents, and then count how many unique names I had. I needed to do it in Lotusscript. I would also need to do something with those names later in my code. Oh, and the number of names would depend on the document collection and how many were actually unique. Addtionally, I had more than one bit of data that I wanted to capture. For this example, we’ll say name and phone number. So, what to do?

Well, I *could* use an array, but not knowing how many names would be added to the array would mean having to ReDim the array, but that’s no fun. So enter Lists! Creating a list is super easy, and you don’t have to know how many items will be in the list. I added a little counter to count the number of items in my list as I added them. Yes, I could have added them, and then looped through afterward and counted them that way, but I actually had some other stuff to do, so did it when I added.

Dim clientList List As String ‘dim the list itself Dim n As Long ‘dim n as long for the counter n = 0 ‘start the count at 0 While Not entry Is Nothing ‘obviously prior code would have dimmed a view entry collection and 'provided a way to loop through it, this part of the code just insures we are acting on an actual entry ‘This next bit checks to see if the item is already in the list and if it is NOT, then increases the counter by 1, 'and adds the entry with column value 5 as the listtag and column value 6 as the value If Not (Iselement(clientList(entry.columnvalues(5)))) Then n = n + 1 clientList (entry.ColumnValues(5)) =entry.columnvalues(6) End If Print Cstr(n) ‘this prints the count of items added to the list ‘This just shows something we can do with the list, such as printing the listtag '(aka column value 5) for all of the entries in the list. Forall clients In clientList Print ListTag(clients) End Forall

ls2html was brought to you by nsftools.com

Pretty easy, huh? Easy to create and easy to use the data. So Lists! Use ‘em!

'

Comments

Gravatar Image1 - Yes, lists are very powerful, and I use them all the time. I actually wrote an article about lists for the View (Nov/Dec 2006, that copy was actually distributed at Lotusphere 2007).

Other cool things you can do with lists is to create lists of objects, either things like NotesDocuments or your own classes/data types.

Example:

Type CarData
Manufacturer As String
Year As String
Color As String
Owner As String
End Type

Dim car List As CarData
car("123XYZ").Manufacturer = "Ford"
car("123XYZ").Color = "Red"

Then you can loop thought the list:

Forall c in car
Print c.Manufacturer & " - " & c.Color
End ForAll



Gravatar Image2 - Amen... very useful and, as you mentioned, underutilized.

Oh, by the way, if you like Lists, you'll adjust well to XPages: with JavaScript's "associative arrays" and Java's Maps, this type of storage model gets used constantly when doing any serious XPage development.

Gravatar Image3 - Love Lists myself, ever since Bill Buchan started beating us over the head a few years ago about them. Karl, I had not thought about using user defined types in that way but already see plenty of uses for them. Nice!

Gravatar Image4 - dear swede in tejas,

man i gave up on Types. i always end up needing a method, seems like. i use Class instead.

using Lists to keep track of objects FTW!

tim,

i say, nice mysterious hand waving over the XPages magic. ok so i do use associatvie arrays in JS. Maps? being a guy, i just don't need maps. i'll get there, it just takes me a few extra days.

Gravatar Image5 - @4: Yeah, I use classes all the time as well, that makes it even more powerful.

licno = "123XYZ"
Set car(licno) = New CarData()
Call car(licno).AddDriver("Karl-Henry Martinsson")
Call car(licno).SetColor = "Silver"
xmldata = car(licno).GetXML()





Gravatar Image6 - I wrote a blog entry with some more production like code (using a class) here: { Link }

Enjoy!

Gravatar Image7 - Thanks Karl! Great stuff!

Gravatar Image8 - @John,

I get there too, with no Maps or Class ;).

It had to be written.

Gravatar Image9 - Yancy, you're like school in summer - you got no class! Emoticon

#FatAlbert

Post A Comment

:-D:-o:-p:-x:-(:-):-\:angry::cool::cry::emb::grin::huh::laugh::lips::rolleyes:;-)