Microsoft KB Archive/101594
PRB: Ampersand Displays as Underscore in Popup
The information in this article applies to:
After you create a popup from an array that has strings as elements, if a element has an ampersand (&) in the string's text, the ampersand displays as "_" (an underscore) instead of "&" in the selected item box of the popup. For example, if the array element was "TEST1 & TEST2", it would display in the selected item box as "TEST1 _TEST2" when selected.
This behavior is caused by a feature of Windows. In Windows, an ampersand indicates that the next character should be underlined; therefore, this behavior also occurs in FoxPro for Windows.
To display an ampersand in Windows, you have to use two ampersands (for example, && Text). However, this workaround cannot be used in FoxPro because a double ampersand indicates that the following text is a comment and FoxPro should ignore the rest of the line, which usually generates a syntax error.
The best resolution for this is not to use ampersands in popups, whether from arrays or lists. The reason for this is that the behavior of some of the workarounds is unreliable and unpredictable.
One workaround that could be acceptable for short popups is to create the popup from a list.
To do this, initialize a variable in the Setup code for each item that needs to contain an ampersand, and then put the variable in the prompt for the popup using macro substitution. For example, in the Setup code, place this line of code:
myvar="TEST1 &"+"& TEST2"
And in the popup prompt's list, enter the variable preceeded by an ampersand(for macro substitution)
Items in the list that do not contain ampersands do not need to be placed in variables. The problem with this resolution is that the items on the list show two ampersands, not just one. But the display value just shows one. Both ampersands get stored to the popup's variable. There is not a good solution for this issue if the popup is from an array and some of the array elements contain text with ampersands. Changing these elements as above can be tried.
Steps to Reproduce Problem
1. From the File menu, choose New, select Screen, and then choose
2. After the Screen Builder is displayed, choose Layout from the
3. In the Screen Layout dialog box, select Code under Options, and
then choose Screen Setup Code.
4. Enter the following screen Setup code:
DIMENSION test(2) test(1)="TEST1 & TEST2" test(2)="TEST3 & TEST4"
5. Select the Popup tool from the toolbox and place a popup on the
6. In the Popup dialog box, select Array Popup and type "test"
(without the quotation marks).
7. In the Variable box, type "x" (without the quotation marks), and
then choose OK.
8. From the Program menu, choose Generate. 9. Save the changes as ZTEST.SCX.
10. After ZTEST.SPR has been generated, type the following command in
the Command window: DO ztest.spr
11. Select TEST3 & TEST4 from the popup. Note that it displays as
Additional reference words: FoxWin 2.60 2.0a KBCategory: kbprg kbprb KBSubcategory: FxprgMacrosub
Last Reviewed: November 17, 1997