Microsoft KB Archive/139214

= How to Store Numeric Values that Come from a Combo Box =

Article ID: 139214

Article Last Modified on 2/11/2000

-

APPLIES TO


 * Microsoft Visual FoxPro 3.0 Standard Edition

-



This article was previously published under Q139214



SUMMARY
When the ControlSource property of a combo box or list box evaluates to a numeric variable and the list box displays numeric data, the ControlSource stores the index number (position) in the list, not the data that is displayed. This article shows by example how to store the numeric value listed in a combo box in a numeric variable.



MORE INFORMATION
The RowSource property of a combo box or list box specifies the source of the values; that is, it indicates where the data is coming from.

The ControlSource property of a combo box specifies the data that is modified when a selection is made. It indicates where the data is going to.

When a combo box is bound to a character variable, the expression displayed in the list is stored to the ControlSource. When the object is bound to a numeric variable, the index order of the expression is stored to the ControlSource. For example, say the list displays the following elements:   -- | 10 |  | 20 |   | 30 |   | 40 |   -- If the number 30 is selected when the data is bound to a numeric variable, the variable stored in the ControlSource property will evaluate to 3, because 30 is the third element in the list. If the data originates from a table, this index can correspond to a record number.

When a combo box or a list box is not bound to any data, ControlSource is empty. The Value property stores the character string that is currently selected. Using the previous example, the Value property is equal to 30 if the list box is not bound to data.

The Visual FoxPro Help file indicates that once the ControlSource property is set to a field or variable, the Value property always has the same data value and the same data type as the variable or field to which the ControlSource property is set.

To store the numeric selection of a combo box to a numeric variable, you can assign the value of the combo box to the variable in the Interactive Change event handler. This assumes that the object is not bound to data. The following step-by-step example illustrates this procedure.

Step-by-Step Example
 Create a new form. Right-click the form, and then click Data Environment. In the Data Environment, open the Orders table located in the Samples\Data directory. Select the form, and place a combo box on the form.  Change the following properties for the combo box: RowSourceType: 2-Alias RowSource   : Orders.order_amt  && Numeric field

Do not assign a ControlSource to the combo box.  Create a new property for the form, and name it nSelectData.</li>  In the InteractiveChange event handler for Combo1, type: THISFORM.nSelectData=VAL(THIS.Value) </li> Save and run the form. To verify the value of the nSelectData variable, open the Debug window and type <Form>.nSelectData, where <Form> is the name of the form.</li></ol>

Additional query words: combobox listbox

Keywords: KB139214

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.