Search DominoPower's 11,429 Lotus-related article archive 
Home
EasyPrint
News details Click here for the RSS feed's XML code. This is not a browser URL.
Articles-only Click here for the RSS feed's XML code. This is not a browser URL.
Twitter Feed Click here for the Twitter feed.
PROGRAMMING POWER
Use the LotusScript Split function to write simpler code
By Mick Moignard

How many times have you declared an array in LotusScript and then tediously initialised the elements in it one-by-one? If you're like me, you've probably initialized with code like:

dim Things(17) as String
Thing(0) = "First"
Thing(1) = "Second"

right down to

Thing(17) = "Seventeenth"

And, if you're like me, you were probably getting quietly bored while you are typing it all, as well as being conscious that these 19 lines of code at the start of the function always mean that you have to scroll down to see the code.

I've done this more than a few times. I've often looked for a better way of doing such a thing -- add to that the fact that as a programmer, I'm a bit lazy, so I'll happily spend a little time looking for something cool that will mean I have to type (and maintain) less code.

This approach is relatively hard to maintain, especially when someone wants a new value "Five and a Half", meaning that not only do you extend the Dim statement, but you then have to renumber all the element references after the change.

The LotusScript Split function, new in Release 6 (yes, that long ago) comes to the rescue here. Designer Help says that Split "Returns an Array of Strings that are the substrings of the specified String", and is used like this:

Split (expression [, delimiter [, count [, compMethod ]]])

where Expression is the string to split up, using the optional Delimiter as the delimiter to split at. The count parameter enables you to have split return the first n split-off values, rather than the whole list, and the last one specifies various ways to search for the delimiter -- options around the case and pitch of the delimiter. The first two, are the important ones.

Using Split on my original example, all I then needed to code would be:

dim Things as Variant
Things = Split("First, Second, Third...... , Seventeenth",",")

This certainly saved some time, and when I have to make the change, all I change is:

dim Things as Variant
Things = Split("First, Second, Third..., Five and a Half, ... , Seventeenth",",")

By now you've probably realised that Split is not a long way away from the functionality offered by @Explode in formula language. You'll also note that, in the example, Things has become a Variant, too. We'll discuss that a bit later on, when we've looked at some more useful things to do with Split than just using it to initialise arrays. Like @Explode, It's a great tool in parsing strings, given a little bit of forethought.


1  ·  2  ·  Next »
Other articles you might like
Home > Lotus Technologies > LotusScript (64 articles)
   When the debugger won't debug hidden code that isn't hidden
   What to do if the LotusScript debugger won't single-step over code
   Little known traps about Lotus Notes fields
Get Weekly Email Updates
Subscribe to our regular weekly email newsletter. It's packed with tips, reviews, deep analysis, and the latest news.
 
Recent DominoPower Articles
Application development, William Shatner, and the origin of the universe
Learn Domino Designer 8.5 for free
The (near) future of Sametime, Quickr, Connections, and Symphony
Inside the IBM Innovations lab
Lotusphere 2010: Hot fixes and cool news for Notes, Domino, and LotusLive
Lotusphere 2010: mobility and collaboration
2010: A Lotusphere of change
Latest Lotus Headlines
IBM Lotus to Google Apps Migration Remorse
Webcast Series: Mobile Collaboration with Lotus Software
Domino Login Control for Mobile Apps
Sys Admin Tips March 2010
Quickr place Superusers
Writing Client-Side Javascript for Re-Use
Lotus Notes R8.5.1: Bug in Contacts "Print Selected View"
>> Read all the news
More from the ZATZ journals
Computing Unplugged: The iPad defenders have spoken
David Gewirtz Online: CNN commentary and analysis
OutlookPower: More about disappearing text
-- Advertisement --

Learn Notes and Domino 8 at your place and pace!
Learn Notes and Domino in your office and/or home! TLCC's highly acclaimed distance learning courses for users, developers, and admins will enhance your career and your resume.

The many included activities and demos will make you a pro! Expert instructor help is a click away.

Click here to try a FREE demo course!!

-- Advertisement --

Mark your calendar for in-depth Lotus training, May 12-14, Boston
Join experts and peers May 12-14 in Boston for educational and networking events that deliver real-world Lotus training so you can increase productivity and efficiency in your company, advance your skills, and squeeze the most from your current environment. One registration gets you into THE VIEW's Admin2010 and Lotus Developer2010.

Register by April 10 to save $200.
ZATZ Home  ·  News  ·  Back Issues  ·  Credits/Trademarks ·  Link To Us
Copyright © 1998-2010, ZATZ Publishing. All rights reserved worldwide.
Editor's Login