|
trak Newbie
Joined: 21 Jan 2002 Posts: 7 Location: Canada
|
Posted: Thu May 23, 2002 8:37 am
Problems with the %pick() function |
I seem to have run into a small problem with the %pick() function. I'm trying to search a database for items, then return the list of items in a pick list. The problem I'm running into concerns a comma in one of the names returned by my db search. Here's a bit of code to clarify:
#NOOP If there's a second argument, search the database
#if (%2) {
@ShowIDQuery = %find( %2)
#if (%numitems( @ShowIDQuery) > 0) {
#forall @ShowIDQuery {#addkey ShowIDHash {%db( %dbget( %i), Name)=%i}}
}
#LOOPDB @ShowIDHash {#additem ShowIDQueryNames %key}
@ShowIDPick = %pick( @ShowIDQueryNames)
...
If one of the records contains a comma, the records is split into two. For example, "a pair of dirty, mudcaked leather boots" becomes "a pair of dirty" and "mudcaked leather boots". %pick("a pair of dirty~, mudcaked leather boots) shows properly, but I'm unable to do that with the string list.
I've tried just about everything I can think of, and nothing seems to work. Any help would be greatly appreciated. TIA
Oh, and #additem ShowIDQueryNames %replace(%key, ",", "~,") doesn't seem to do anything either. |
|
|
|
Pega Magician
Joined: 08 Jan 2001 Posts: 341 Location: Singapore
|
Posted: Thu May 23, 2002 11:34 am |
Due to the nature of the %pick() function it is not easy for it to differentiate between when you want to use commas as seperators or plain text.
Instead of using the %pick() function, use the #pick command. I think this hack might work, no gaurantees.
#LOOPDB @ShowIDHash {#additem ShowIDQueryNames "%key:#var ShowIDPick %key"}
#PICK %remove(")",%remove("(",%additem(@gtest,p:Select an item:|o:1))) |
|
|
|
Vijilante SubAdmin
Joined: 18 Nov 2001 Posts: 5182
|
Posted: Thu May 23, 2002 10:29 pm |
If you are bent on using %pick try adding more ~'s in the replace.
"~~," should work as that will actually put a tilde into the variable. However when you reference the variable that may get used up before pick looks at it. In that case "~~~~," will work. It should be the first one though.
The other option is to change only this line, '@ShowIDPick = %pick( @ShowIDQueryNames)' to '@ShowIDPick = %pick( %replace(@ShowIDQueryNames,",","~,"))' |
|
|
|
Pega Magician
Joined: 08 Jan 2001 Posts: 341 Location: Singapore
|
Posted: Fri May 24, 2002 9:13 am |
Nice Vijilante, I tested #noop %pick(%replace(@ShowIDQueryNames,",","~,")) and it seems to work just fine.
By the way, my script can be changed to:#LOOPDB @ShowIDHash {#additem ShowIDQueryNames "%key:#var ShowIDPick %key"}
#PICK {p:Select an item:|o:1|@ShowIDPick} |
|
|
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|