|
|
|
|
|
|
|
|
|
|
|
|
|
|
Use the LotusScript Split function to write simpler code (continued)
Here's a simple example. I wanted to generate a filename with the date as part of the name. I'd get the date and time with @Now, but of course here in the UK, dates derived from @Now have "/" in them as the data separator, and ":" as the time separator. Neither of those characters are allowed in file names.
Conventional coding tediously iterates the string, examining each character with Instr() and replacing as relevant. Not any longer. Using Split and Replace, you can fix this in one statement -- note that Replace likes arrays for the second and third parameters:
wipdatafile = "WipData " & Replace(Cstr(Now), Split("/ :"), Split("- -")) & ".csv"
|
This code replaces the slash and semicolons in the time string with hyphens.
A more complex example Now here's a more complex scenario that I've recently used. I had a view that I presented to the user for selection, in a Picklist displayed by a button on a form. I wanted to populate six fields on this form from data values in the document selected by the user. What I did was this:
Step 1
I added a hidden column to the end of the view, that concatenated the values I required together into one value,and I separated these values with "**". So my view column formula looked something like
StreetAddress + "**" + Town + "**" + County + "**" + Country + "**" + PostCode
|
And remember, of course, that for even better view performance, you could always create a field on the document using the same formula, and have the view display that field value.
Step 2
The Picklist formula used then pulls that column back into the code -- in this case it was the 7th (starting from zero) column:
dim selection as variant
selection = workspace.PickListStrings(PICKLIST_CUSTOM,False,doc.server(0), doc.addressfile(0),"ADDRESSES", "Select Address","Select the required address:",7)
If Isempty(selection) Then Exit Sub 'Cancel pressed
|
Step 3
I then split the address back up into the constituent fields:
selection = Split(Cstr(selection(0)), "**",-1) 'makes selection into a 5-element array of strings
|
Step 4
Finally, assign them as required:
doc.Street = selection(0)
doc.Town = selection(1)
doc.County = selection(2)
doc.Country = selection(3)
doc.PostCode = selection(4)
|
The value of this process is that there was only one trip to look up data, with all the data required being pulled back in the one operation. For sure, I could have obtained a key value from the Picklist operation, and then used that to look up the values I needed, but this way means that I only did the one database operation, and also ended up with simple and pretty elegant code.
There's also less that can go wrong here, too.
So why do I have to use a Variant to contain the results from Spilt, when the Designer help says that it returns an array of strings? Well, it's because the LotusScript compiler can only cope with references to string arrays on the left of an array assignment when it can be sure of exactly what is going on -- the dimensions of the array -- at compile time. In this case, it can't tell at compile time, even if I know what they will be as I write the code, so you return values to a variant, which will then contain be an array of strings.
Brent Hawthorne is Assistant Vice President for Network Computing and Groupware at Western Interstate Bancorp. He prefers the great outdoors to work, but finds it doesn't pay nearly as well. He can be reached at brent_hawthorne@firstplus.com.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- 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. |
|
|
|
|
|
|
|
|
|
|