Search DominoPower's 11,323 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
Lotusphere 2010: mobility and collaboration
2010: A Lotusphere of change
Five trends for 2010
DominoPower TV Episode 1: Inside a strategy session with Teamstudio
More about Domino log files
Say goodbye to the Uh-Ohs. Long live the Tens.
Why your log.nsf might not be purging properly
Latest Lotus Headlines
Recommended Maintenance - Lotus Notes Traveler
Here are the slides and other materials from our Lotusphere session
Microsoft OCS awareness in Lotus Connections and Websphere Portal?
SnTT: XPages Blank Calendar Control (Part 2), adding data
Have your Lotus Notes calendar display multiple time zones
Sample Database for Microsoft Office and Lotus Symphony Integration
Symphony 3.0 beta signals another attack on Office
>> Read all the news
More from the ZATZ journals
Computing Unplugged: The iPad: Apple's latest heartbreaker
David Gewirtz Online: CNN commentary and analysis
OutlookPower: Running auto-respond rules when Outlook is closed
-- Advertisement --

Power Tools 6.0 is a set of 90 administrative utilities for Lotus Notes & Domino
Power Tools simplifies management of the Notes/Domino environment by automating routine tasks. Power Tools can manage or monitor mail files, groups, ACLs, agents, LOG.NSF, templates and more.

Download a trial version from helpsoft.com.
-- Advertisement --

Struggling with exporting Notes data to spreadsheets? No More!
Try IntelliPRINT, The world's leading Reporting, Dashboards, and Analysis solution for Notes & Domino

  • Don't spend unproductive time maintaining different versions of the same spreadsheet
  • Preserve data integrity and security in multi-user environments
  • Create reports in minutes INSIDE Notes
  • Get freedom from iterative report requests, deliver self-serve capabilities

Experience Reporting, Dashboards, and Analysis INSIDE Notes.

Try IntelliPRINT NOW!

ZATZ Home  ·  News  ·  Back Issues  ·  Credits/Trademarks ·  Link To Us
Copyright © 1998-2010, ZATZ Publishing. All rights reserved worldwide.
Editor's Login