listbox method select()

new BookmarkLockedFalling
incisor
New Member
*

incisor Avatar

Posts: 5

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.
StefanPendl
Global Moderator
*****

StefanPendl Avatar

Run for BASIC ...
Posts: 945

[b]Stefan[/b] - [a href=http://stefanpendl.runbasichosting.com/]Homepage[/a][br][br][b]Please give credit if you use code I post, no need to ask for permission.[/b][br][br]Run BASIC 1.01, Fire-/Waterfox (IE11, Edge), Windows 10 Professional x64, Intel Core i7-4710MQ 2.5GHz, 16GB RAM
incisor
New Member
*

incisor Avatar

Posts: 5

incisor
New Member
*

incisor Avatar

Posts: 5

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.
incisor
New Member
*

incisor Avatar

Posts: 5

StefanPendl
Global Moderator
*****

StefanPendl Avatar

Run for BASIC ...
Posts: 945

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
[b]Stefan[/b] - [a href=http://stefanpendl.runbasichosting.com/]Homepage[/a][br][br][b]Please give credit if you use code I post, no need to ask for permission.[/b][br][br]Run BASIC 1.01, Fire-/Waterfox (IE11, Edge), Windows 10 Professional x64, Intel Core i7-4710MQ 2.5GHz, 16GB RAM
Psycho
Full Member
***

Psycho Avatar

Posts: 196

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
colinmac
Junior Member
**

colinmac Avatar

Posts: 58

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
StefanPendl
Global Moderator
*****

StefanPendl Avatar

Run for BASIC ...
Posts: 945

[b]Stefan[/b] - [a href=http://stefanpendl.runbasichosting.com/]Homepage[/a][br][br][b]Please give credit if you use code I post, no need to ask for permission.[/b][br][br]Run BASIC 1.01, Fire-/Waterfox (IE11, Edge), Windows 10 Professional x64, Intel Core i7-4710MQ 2.5GHz, 16GB RAM
colinmac
Junior Member
**

colinmac Avatar

Posts: 58

StefanPendl
Global Moderator
*****

StefanPendl Avatar

Run for BASIC ...
Posts: 945

[b]Stefan[/b] - [a href=http://stefanpendl.runbasichosting.com/]Homepage[/a][br][br][b]Please give credit if you use code I post, no need to ask for permission.[/b][br][br]Run BASIC 1.01, Fire-/Waterfox (IE11, Edge), Windows 10 Professional x64, Intel Core i7-4710MQ 2.5GHz, 16GB RAM