How to Use a Portion of a Memo Field in a List Box

ID: Q111672

2.50 2.50a 2.50b 3.00 | 2.00 2.50 2.50a 2.50b | 2.50b

WINDOWS               | MS-DOS                | MACINTOSH

The information in this article applies to:
  • Microsoft Visual FoxPro for Windows, version 3.0
  • Microsoft FoxPro for Windows, versions 2.5, 2.5a, and 2.5b
  • Microsoft FoxPro for MS-DOS, versions 2.0, 2.5, 2.5a, and 2.5b
  • Microsoft FoxPro for Macintosh, version 2.5b

SUMMARY

This article describes how to effectively use a portion of a memo field in a list box object that is part of a user-defined screen.

MORE INFORMATION

To illustrate how to use a portion of a memo field in a list box object, suppose that the first 40 characters of the memo field are needed for the list box.

If a list box object is created using the Screen Builder and the List Items From Field option is selected, then a reasonable expression to enter in the field expression dialog window is:

   LEFT(<memo field name>,40)

This expression will work well as long as all the first lines of all the memo fields in each record are at least 40 characters. If this is not the case, for example, if some of the memo fields have first lines that are less than 40 characters, the above statement will return the carriage return (CR) and linefeed (LF) characters and display them in the list box. Since this is not a desirable side-effect, the following two expressions will correct this situation.

NOTE: Although the first expression works well, the second expression provides a more concise solution.

   LEFT(<memo field name>,IIF(AT(CHR(13), <memo field name>);
        <40,AT(CHR(13),<memo field name>)-1,40))

   -or-

   LEFT(MLINE(<memo field name>,1),40)

The second expression works because the MLINE() function is going to return the characters for the first line of the memo field, up to but not including the CR/LF characters.

The only thing to watch out for concerning the second expression is the current SET MEMOWIDTH value (the default line length is 50 characters). If the MEMOWIDTH is less than 40, no error will result, but only the number of characters corresponding to the MEMOWIDTH value will be returned. For example, if the MEMOWIDTH value is 35, only 35 characters will be returned from the second expression.

Additional reference words: VFoxWin FoxMac FoxDos FoxWin 2.00 2.50 2.50a 2.50b listbox KBCategory: KBSubcategory: FxtoolSbuilder

Keywords          : kbcode FxtoolSbuilder 
Version           : 2.50 2.50a 2.50b 3.00 | 2.00 2.5
Platform          : MACINTOSH MS-DOS WINDOWS


Last Reviewed: May 22, 1998
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.