Setting the Text and Value Properties of Items in a Choice List Array
Description
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.
Example
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 combo.choice.list.redim(count) 'populate the list box tbl.fetch_first() for i = 1 to count combo.choice.list[i].text = trim(tbl.customer) combo.choice.list[i].value = trim(tbl.customer) tbl.fetch_next() 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"
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