PRB: List Box Shows .F. from an Empty ArrayID: Q137182 The information in this article applies to:
SYMPTOMSA list box on a form displays .F. when the RowSource property is set to a dimensioned array, as opposed to an array initialized from an SQL statement, a view, or a remote view. Furthermore, when your redimension the array and pass a value to the new element, the list box does not reflect the new value.
CAUSEArrays, by nature, have a default logical (.F.) data type. If the list box is not properly refreshed, it will not reflect the current values in the array.
RESOLUTIONIn the Init event for the form, change the data type to match the data being passed to it. For example, if you are passing a character string to the first element of the array, issue this command:
STATUSThis behavior is by design.
MORE INFORMATIONMake the array a property of the form. Open your form in the Form Designer. On the Form menu, click New Property. Then type the name of the array, and make sure you give it at least one element or row as in this example:
Then add the following code to the Load event:
If you run the form at this time, you will observe that the list box is
blank. If you had not set the data type to character in this example, you
would have seen the familiar .F. value displayed.
You can test this without a form by dimensioning an array from the Command window:
Open the Debug window (on the Tools menu, click Debug Window). In the left
partition of the Debug window, type the following lines in order:
The values for these are .F., 1, and .T. respectively. The first line shows
you the default data type. The second shows you the length or number of
elements (or number of rows in a single-column array) in the array. The
third shows you the results from the evaluation of whether the element is
empty or not.
In the Command window, type:
The value in the debug window for test(1) changes to "". This tells you
that it is now a character data type with no string assigned to it. Now you
can apply this to a form in Visual FoxPro.
Steps to Reproduce Behavior1. Create a form. Accept the default form and object names (form1, text1, 2. Add a text box, a list box, and a command group to the form. The order
3. On the Form menu, click New Property. Then type test(1) in the Name
4. Right-click the form, and click Properties.
5. Select the list box from the Object menu in the Properties window.
6. On the Object menu in the Properties window, click Commandgroup1.
7. On the Object menu in the Properties window, click Command2 under
8. On the Object menu in the Properties window, click Command3 under
9. Click the red exclamation mark on the Standard toolbar to run the form.
10. Enter your last name in the Text1 box, and click UPDATE. Your last name
11. Enter your first name in the Text1 box, and click UPDATE. Your first
12. Enter your middle name in the Text1 box, and click UPDATE. Your middle
13. Click the SORT button. You will see the names sorted in alphabetical
14. When you are finished, click EXIT. Your form will disappear.
Additional reference words: 3.00 VFoxWin KBCategory: kbprg kbprb kbcode KBSubcategory: FxprgGeneral |
Last Reviewed: September 26, 1995 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |