|
Post by incisor on Jan 20, 2011 0:18:40 GMT -5
I would like to set a listbox to show a specific value that may change at run time .Can I preset the list box to display any of the avaiable list choices with the select() method. The help file definition seems like it should do this.' #handle SELECT(n) - Set the current selection to be the nth item. or would this just be setting the value in memory.
|
|
|
Post by StefanPendl on Jan 20, 2011 4:32:28 GMT -5
SELECT(N) will select the item at index N and highlight it, so the user knows, that this is the current selection.
|
|
|
Post by incisor on Jan 20, 2011 11:16:54 GMT -5
Could you show a simple example, the proper syntax is escaping me.
|
|
|
Post by incisor on Jan 20, 2011 15:42:00 GMT -5
Tried the example but...
************************ dim colorChoices$(2) colorChoices$(0) = "red" colorChoices$(1) = "green" colorChoices$(2) = "blue"
print "Choose a color and click Accept."
listbox #colors, colorChoices$(), 3 #colors select(1)
print link #acceptColor, "Accept", [accept] print wait
[accept]
'#colors select(1)
print "You chose "; #colors selection$() print "You chose "; #colors selection()
wait
**************** ... not what I was expecting for results and the there is no highlight on any of the list box values as expected. results You chose 1 You chose 1
I am confuzzeled.
|
|
|
Post by incisor on Jan 20, 2011 15:52:10 GMT -5
Also the above was done without making a selectoin from the list.. just clicked accept.
|
|
|
Post by StefanPendl on Jan 20, 2011 18:50:10 GMT -5
It seems, that there is the second syntax for the select command missing from the help file.
The below code gives the expected result for a list box that uses a string array.
dim colorChoices$(2) colorChoices$(0) = "red" colorChoices$(1) = "green" colorChoices$(2) = "blue"
print "Choose a color and click Accept."
listbox #colors, colorChoices$(), 3 #colors select("green")
print print "I chose "; #colors selection$() print "I chose "; #colors selection() print link #acceptColor, "Accept", [accept] print wait
[accept] print print "You chose "; #colors selection$() print "You chose "; #colors selection() end
|
|
|
Post by Psycho on Jan 25, 2011 15:49:36 GMT -5
I'm a little late on this but changing this one line on your original code should get the expected result: #colors select(colorChoices$(1)) where you choose the desired array index number. Prior to that, your code did not clearly show what index 1 was for. Below is your original code with updated line: dim colorChoices$(2) colorChoices$(0) = "red" colorChoices$(1) = "green" colorChoices$(2) = "blue"
print "Choose a color and click Accept."
listbox #colors, colorChoices$(), 3 #colors select(colorChoices$(1))
print link #acceptColor, "Accept", [accept] print wait
[accept]
'#colors select(1)
print "You chose "; #colors selection$() print "You chose "; #colors selection()
wait
John "Psycho" Siejkowski
|
|
|
Post by colinmac on Feb 28, 2012 11:43:54 GMT -5
Hello All, I have tried various combinations of the code above, and the code form the help file example, and I cannot get #listbox selection() method to return anything sensible. It will normally return 0, else it returns the last value set with #listbox select(). It is not responsive to user interaction.
Is this method broken? I am using 1.0.1 build 2.44
Colin
|
|
|
Post by StefanPendl on Feb 28, 2012 14:18:50 GMT -5
SELECTION() is only meant to be used with list boxes containing numerical data. For list boxes with string data you need to use SELECTION$().
|
|
|
Post by colinmac on Feb 28, 2012 18:36:40 GMT -5
Ok Stefan,
I will revert to my old method of building the listbox array with an index at the start of each element and reading with val(#listbox selection()). Pity though!
Colin
|
|
|
Post by StefanPendl on Feb 29, 2012 2:32:17 GMT -5
You don't need VAL(), since SELECTION() already returns a number.
|
|