![]() |
Home Email me SEARCH |
Adeleida
Alan Bell
Alan Lepofsky
Andy Donaldson
Arne Nielsen
Ben Langhinrichs
Ben Poole
Bill Buchan
BlogSphere
Brian Benz
Bruce Elgort
Captain Oblivious
Carl Tyler
Chris Byrne
Chris Coates
Chris Linfoot
Chris Miller
Chris Toohey
Chris Whisonant
Christian Brandlehner
CodeStore
Craig Schumann
Curt Stone
Damien Katz
Declan Lynch
Devin Olson
DomBlog.de
domlike.net
Duffbert
Ed Brill
Fabian Nirman
Ferdy Christant
Gayle Elgort
Grant Bingham
Gregg Eldred
Hassan Voyeau
Heini Schwammerl
Ian Irving
Jack Dausman
Jens-Christian Fischer
Jerry Carter
Johan Känngård
John Mill
John Roling
John Vaughan
Just Enough Governance
Justin Knol
Kathy Sierra
Keith Strickland
Ken Yee
Kevin Pettitt
Kurt Higley
Lance Spellman
Laurette Rynne
Mac Guidera
Matt and Jess
Matt White
Mikkel Heisterberg
Mrs Elsmore
Nathan Freeman
News4Notes
nsftools
OpenNTF Blog
Paul Mooney
PhotoTechno Reflections
Ray Bilyk
Richard Schwartz
Richard Spense
Rob Novak
Rob Wunderlich
Rocky Oliver
Roy Holder
Scott Good
Sean Burgess
Simon Peek
Squirrelly Notes
Stan Rogers
Stephan H. Wissel
Steve Castledine
Susan Bulloch
Taking Notes
Tim Rynne
Tim Tripcony
Tom's Rant
Turtle
Vince Schuurman
Volker Weber
Warren Elsmore
Yesterday I needed to update a formula used to generate a list of choices for a field. The existing formula was 20 lines with various @Replace and @SubString, etc. This was necessary in earlier versions of Notes in order to parse the prefixes on each of the potential values. Fortunately, this client site is running ND6, so I was able to replace what would have been about 30 lines of code (after the modifications) with a few lines similar to what's shown here:
tAllValues := @Trim(@DbLookup( ""; ""; "myLookupView"; "myKeyField"; 2));
tWantedPfx := "Prefix1\\" : "Prefix2\\" : "Prefix3\\";
@For( n :=1; n <=@Elements( tAllValues ); n := n + 1;
tList := @If( @Begins( tAllValues[n]; tWantedPfx ); tList : tAllValues[n]; tList ));
@Sort( @Trim(tList) )It's a great feeling to be able to go into code that's been around for quite a while and take advantage of current features to dramatically ease the future maintenance. Life is good :)
1. Posted by Rock - website09/09/2007 08:42 PM
Well, no good code goes unmodified. You can make it even shorter (and faster) using @Transform. Consider:
tAllValues := @Trim(@DbLookup( ""; ""; "myLookupView"; "myKeyField"; 2));
tWantedPfx := "Prefix1\\" : "Prefix2\\" : "Prefix3\\";
@Sort(@Trim(@Transform(tAllValues; "X"; @If( @Begins( X; tWantedPfx ); X; "" ))));
Try that out sometime 
Rock
2. Posted by Joe Litton - website09/09/2007 08:42 PM
Rock,
That @Transform is awesome! I just tested it and it works like a champ. It has now been placed where I'd had the @For. Dang, looks like I've got some refresher studying to do!

3. Posted by Paul09/09/2007 08:42 PM
I wrote my first @For formula not too long ago and it was strange to use a loop in formula. I had to set the value of a field depending on if any known values were contained in a multi-value field.
values := "value1":"value2":"value3";
Flag := @False;
@For(n :=1; n<=@Elements(multivaluefieldname); n:= n + 1;@If(multivaluefieldname[n]=values;Flag:=@True;@Success));
FIELD otherfield := @If(Flag;"newvalue1";"newvalue2");
SELECT @All
4. Posted by david09/09/2007 08:42 PM
my in-house notes guru, Wendy, suggested using the new @nothing as well:
tAllValues := @Trim(@DbLookup( ""; ""; "myLookupView"; "myKeyField"; 2));
tWantedPfx := "Prefix1\\" : "Prefix2\\" : "Prefix3\\";
@Sort(@Transform(tAllValues; "X"; @If( @Begins( X; tWantedPfx ); X; @Nothing )));











