Microsoft KB Archive/285221

= PRB: &quot;There is Not Enough Memory&quot; Error with Menu in a Defined Window =

Article ID: 285221

Article Last Modified on 8/27/2002

-

APPLIES TO


 * Microsoft Visual FoxPro 5.0 Standard Edition
 * Microsoft Visual FoxPro 5.0a
 * Microsoft Visual FoxPro 6.0 Professional Edition

-



This article was previously published under Q285221



SYMPTOMS
If a menu in a defined window is activated more than once, the following error may occur:

There is not enough memory to complete this operation.

NOTE: This problem does not occur in Visual FoxPro 3.0.



RESOLUTION
There are two ways to work around this problem:
 * Display the menu in the main Visual FoxPro Window instead of defining a window. See the two comments in the code labeled &quot;workaround 1&quot; in the &quot;More Information&quot; section&quot;.
 * Define the window before the loop, and instead of releasing the window, deactivate it. See the three comments in the code labeled &quot;workaround 2&quot;.



Steps to Reproduce Behavior
  Create a program file containing the following code: CLEAR ALL SET DEVICE TO SCREEN CLEAR WINDOWS

PUBLIC cLastPad, nLastKey, cLastBar LOCAL cTest && Variable used for the READ

cLastPad = 'PADONE'    && Record which pad was chosen cLastBar = 1           && Record which bar was chosen cTest = SPACE(20)

DEFINE MENU TestMenu COLOR BG/W,N/W,N/W,B/W,W+/B,N/BG,W+/W,N+/N,B/W,W/N,+ DEFINE PAD PadOne OF TestMenu PROMPT 'Pad One'   AT 03,05 DEFINE PAD PadTwo OF TestMenu PROMPT 'Leave Test' AT 03,20

DEFINE POPUP PopOne FROM 04,05 SHADOW DEFINE BAR 1 OF PopOne PROMPT 'Causes Error'

DEFINE POPUP PopTwo FROM 04,20 SHADOW DEFINE BAR 1 OF PopTwo PROMPT 'Exit To FoxPro'

ON PAD PadOne OF TestMenu ACTIVATE POPUP PopOne ON PAD PadTwo OF TestMenu ACTIVATE POPUP PopTwo ON SELECTION POPUP PopOne DO mainproc WITH PAD, BAR ON SELECTION POPUP PopTwo DO mainproc WITH PAD, BAR

* Workaround 2. Uncomment the next 2 lines and be sure to  * comment out the lines for the window definition inside the * WHILE loop
 * DEFINE WINDOW Main FROM 0,0 to 24,79 NONE NOCLOSE NOFLOAT;
 * NOGROW NOSHADOW NOZOOM COLOR W/B

DO WHILE .T.  IF cLastPad # 'PADTWO' * Comment out the next 3 lines for a workaround 1 to the problem. * If you are trying workaround 2 only comment out the next * 2 lines DEFINE WINDOW Main FROM 0,0 to 24,79 NONE NOCLOSE NOFLOAT; NOGROW NOSHADOW NOZOOM COLOR W/B ACTIVATE WINDOW Main   && Window for main menu DO WHILE .T.        nLastKey  = 0                 && Initialize LASTKEY ACTIVATE MENU TestMenu PAD &cLastPad * Check to see if no key was pressed or the ESC key IF nLastKey = 0 OR nLastKey = 27  THEN LOOP ELSE EXIT ENDIF ENDDO ENDIF

DO CASE CASE cLastPad = 'PADONE' * Comment out next line for both workarounds to the problem. RELEASE WINDOW Main * Uncomment the next line for workaround 2. *DEACTIVATE WINDOW Main @ 2,4 SAY &quot;Press ESC Or ENTER To Go Cause Error&quot; GET cTest READ CLEAR CASE cLastPad = 'PADTWO'  && Return to Fox EXIT ENDCASE ENDDO CLEAR ALL RETURN
 * This point is reached when a choice is made on the menu and it is deactivated.

PROCEDURE mainproc PARAMETERS mpad, mbar
 * This procedure stores the selection, and then deactivates the menu to
 * trigger the CASE structure for branching. Note that the passed value
 * of BAR is zero if the ESC key was pressed.

nLastkey = LASTKEY cLastPad = mpad          && Store selection in public var cLastBar = mbar          &&   &quot;       &quot;      &quot;    &quot;    &quot; DEACTIVATE MENU TestMenu && Go to CASE to process selection RETURN  Run the code and then select the first menu option. Press ESC or ENTER to return to the menu.

The error message described in the &quot;Symptoms&quot; section is displayed.

Keywords: kbcodesnippet kbprb KB285221

-

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

© Microsoft Corporation. All rights reserved.