PRB: Ampersand Displays as Underscore in Popup

Last reviewed: November 17, 1997
Article ID: Q101594

The information in this article applies to:

  • Microsoft FoxPro for Windows, versions 2.6 and 2.6a

SYMPTOMS

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.

CAUSE

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.

RESOLUTION

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)

   &myvar

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.

MORE INFORMATION

Steps to Reproduce Problem

  1. From the File menu, choose New, select Screen, and then choose New.

  2. After the Screen Builder is displayed, choose Layout from the Screen menu.

  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 screen.

  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 TEST3 _TEST4.


Additional reference words: FoxWin 2.60 2.0a
KBCategory: kbprg kbprb
KBSubcategory: FxprgMacrosub


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: November 17, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.