Setting the Text and Value Properties of Items in a Choice List Array


The user defined choices displayed by a combo box, radio button, list box etc. can be read and set by reading or setting the text and value properties of the choice list array. The text property controls what is displayed on the form. The value property controls what value is written to the field when an item is selected.

A user defined choice list array is not a normal data array, as Documented by the <ARRAY> Methods. A choice list array has its own special methods. Also, This technique does not apply if the control's choices were populated with Xbasic. In that case you need to manipulate the control's .settings.dynamic_list property.


The following script checks the value of the which_state control on the form and then runs a query to select customers in that state. It then populates a list box called "combo" with the results of the query.

tbl = table.current()
'run the query
'See note at end regarding next two lines
state_to_query = which_state.value
query.filter = "state = state_to_query"
query.order = "last_name"
indx = tbl.query_create()
count = indx.records_get()
'redimension the list box
'populate the list box
for i = 1 to count
    combo.choice.list[i].text = trim(tbl.customer)
    combo.choice.list[i].value = trim(tbl.customer)
next i

The following script inserts 2 new choice into the radio button group called Radio. The group has "MC, Visa, and Amex" as its initial 3 choices. The new choices are inserted after "Visa". The script is on a button on a form.

radio.choice.list.insert(2,2) 'insert 2 items after item 2
radio.choice.list[3].text = "Diners Club"
radio.choice.list[3].value = "DC"
radio.choice.list[4].text = "Discover"
radio.choice.list[4].value = "D"
The Query.Filter expression cannot directly refer to layout level variables on the form, or to form controls, or the table pointer. Your script must set a local script variable to the value of the layout level variable, or the form control. Alternatively, declare variables on the form as Session level. For example, the following code does not work:
query.filter = "state = which_state.value"

Whereas, this code does work:

state_to_query = which_state.value
query.filter = "state = state_to_query"

See Also