Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
List Box Choice becomes variable text
#1
Hi All,
I know there must be a shortcut for doing this just can't seem to figure it out. I have a listbox with a large number of names in the form:

Macro
Code:
Copy      Help
sel(list("Name1[]name2[]Name3[]Name4[]etc..." "test" "test"))

The only options I have for dealing with the user choice is to break it down in cases like this:

Macro
Code:
Copy      Help
,case 1
,case 2
,case 3
,case 4
,case else ret

or storing it into variable _i as numbered index.

But my case is very simple: the text of the users choice (e.g. Name2) is assigned to a certain variable (e.g. NameChoice)

I know I could write that out for each case but it seems too brute force - I am sure there is an elegant much shorter way of doing it!

Thanks for any help,
Stuart
#2
str s="name1[]name2[]..."
_i=sel(list(s ...
if(!_i) ret
ARRAY(str) a=s
out a[_i-1]
#3
Amazing answer - I figured it was something with an array but your solution is so elegant. I think that it might be a good menu choice option for a future version of QM.
Thanks so much!!!!!!
Stuart


Forum Jump:


Users browsing this thread: 1 Guest(s)