Re: loop never exits on ESC

From: rajani (rajani_at_discussions.microsoft.com)
Date: 12/09/04


Date: Wed, 8 Dec 2004 21:01:02 -0800

Sietse
I just added following command in my code
ON KEY LABEL ins MESSAGEBOX('hi')

but no matter how many times i press INS key i dont get any messagebox.
if run the abv command in command window then it works!

"Sietse Wijnker" wrote:

> Hi Rajani,
> You've placed the ON ESCAPE within the loop. You should place the ON ESCAPE
> outside the loop. It functions much like the ON KEY LABEL.
> Once set, the command that should be executed is stored.
> Also, to avoid scope-issues, the cancel variable can be made public:
> *- Start of method
> PUBLIC glCancel
> ON ESCAPE glCancel = .T.
>
> *- your code here...
>
> *- End of method
> ON ESCAPE
> RELEASE glCancel
>
> When this is in place, you can remove the INKEY() code block
> To also check for the insert key, you can place this code after the ON
> ESCAPE glCancel = .T. line:
> IF gldevelop
> ON KEY LABEL Ins glCancel = .T.
> ENDIF
>
> Also dont forget to reset it:
> ON KEY LABEL Ins
>
> As for debugging, you might want to create a breakpoint on a specific line.
> Then set the passcount on the breakpoints dialog form (Ctrl+B) to break
> after a specific amount of times the line has executed. You could also try
> to add a watch expression testing the glCancel and setting a breakpoint on
> that.
>
> HTH,
> Sietse Wijnker
>
> "rajani" <rajani@discussions.microsoft.com> wrote in message
> news:E3354DE7-D817-4AE3-976F-FD2DAB1E8364@microsoft.com...
> > Sietse
> > Yes,i am calling form Refresh method & even tried doevents but no avail.
> >
> > actual code is(hope that make sense :-) i added comments wherver posible.
> >
> > LOCAL lnTime, lnNext, lnCnt, ldStart
> >
> > lnTime = -1 && Starting time
> >
> > * Start search at current date time unless otherwise specified
> > IF EMPTY(tdStart)
> > tdStart = TTOD(THIS.tDate)
> > * Start searching at the end of the current slot
> > lnTime = THIS.GetSlotTime(THIS.GetCurrentRow()) +
> > THIS.GetSlotDuration(THIS.GetCurrentRow()) - 1
> > ENDIF
> > IF !EMPTY(tnStartTime)
> > lnTime = tnStartTime
> > ENDIF
> >
> >
> > * Search result vars
> > ldStart = tdStart && date iterator
> > lnSearch = -1 &&populated when search sucessful
> > llCancel = .F. && cancelled search indicator
> > lcResource = THIS.cCurrentPageOwner && default pageowner
> >
> > ncnt=0
> >
> > * loop through each day from search date
> > DO WHILE .T.
> > ncnt = ncnt +1
> >
> >
> > FOR lnCnt = 1 TO IIF(tlAllPageOwners,
> > THIS.oToolbar.GetArrayLength(THIS),1)
> > *ALEN(THIS.oToolbar.aPageOwners,1), 1)
> >
> > * set the resource (if all pageowners required in search)
> > IF tlAllPageOwners
> > lcResource = THIS.oToolbar.GetPageOwner(THIS,lnCnt,2)
> > *THIS.oToolBar.aPageOwners[lnCnt,2]
> > ENDIF
> >
> > * Set relevant filters
> > THIS.Shift.SetFilter( DTOT(ldStart) , lcResource)
> > THIS.Booking.SetFilter(DTOT(ldStart) , lcResource)
> >
> > lnIndex = lnTime
> >
> > lnFree = 0 && incrementer totalling consecutive free time
> > lnFreeStart = -1 && starting time of current free space total
> >
> > DO WHILE .T.
> > ON ESCAPE llCancel =.t.
> >
> > * allow ESC or insert (for dev) to cancel seach
> > lnKey = INKEY()
> >
> > IF lnKey = 27 OR (gldevelop AND lnkey = 22) && this code never works
> > llCancel = .T.
> > EXIT
> > ENDIF
> >
> > lnNext = 9999
> >
> > * Get next slot from shift setup
> > lnShift = THIS.Shift.GetNextTime(lnIndex,.T.)
> > lnNext = MIN(lnNext,lnShift)
> >
> > * Get next booking
> > lnBooking = THIS.Booking.GetNextTime(lnIndex,.T.)
> > lnNext = MIN(lnNext,lnBooking)
> >
> > * if no further slots, exit
> > IF lnNext = 9999
> > EXIT
> > ENDIF
> >
> > DO CASE
> > CASE lnBooking == lnNext
> > * Fakedraw sets the booking.nend property
> > THIS.Booking.FakeDraw()
> > IF THIS.Booking.Free() AND;
> > (EMPTY(tcType) OR THIS.Booking.cType == tcType);
> > AND (TYPE('toHook') != 'O' OR toHook.ValidBooking(booking.pkey,1))
> > lnFree = lnFree + THIS.Booking.nSlotSize
> > IF lnFreeStart = -1
> > lnFreeStart = lnNext
> > ENDIF
> > ELSE
> > lnFree = 0
> > lnFreeStart = -1
> > ENDIF
> > * ensure search continues from the END of the booking
> > IF THIS.Booking.nEnd > 0
> > lnNext = THIS.Booking.nEnd - 1
> > ENDIF
> >
> > CASE lnShift == lnNext
> > IF (EMPTY(tcType) OR THIS.Shift.cType == tcType);
> > AND (TYPE('toHook') != 'O' OR
> > toHook.ValidBooking(THIS.shift.cShiftKey,2))
> >
> > lnFree = lnFree + THIS.Shift.nSlotSize
> > IF lnFreeStart = -1
> > lnFreeStart = lnNext
> > ENDIF
> > ELSE
> > lnFree = 0
> > lnFreeStart = -1
> > ENDIF
> > ENDCASE
> >
> > * if free length enough (successful search), exit
> > IF lnFree >= tnLength AND !EMPTY(lnFree)
> > lnSearch = lnFreeStart
> > EXIT
> > ENDIF
> >
> > * update the search index
> > lnIndex = lnNext
> > WAIT WINDOW NOWAIT "count value "+TRANSFORM(ncnt)
> > IF llCancel OR ncnt>600 && i just added this to force exit
> > llCancel = .T.
> > EXIT
> > ENDIF
> > ENDDO
> >
> > * test for sucessful search , or cancel
> > IF lnSearch > -1 OR llCancel
> > EXIT
> > ENDIF
> >
> > ENDFOR
> >
> > * test for sucessful search , or cancel
> > IF lnSearch > -1 OR llCancel
> > EXIT
> > ENDIF
> >
> > * increment date
> > ldStart = ldStart + 1
> >
> > * test for search end date
> > IF !EMPTY(tnEnd) AND GOMONTH(tdStart,tnEnd) < ldStart
> > EXIT
> > ENDIF
> >
> > lnTime = -1 && ensure subsequent days start at earliest
> >
> > * update the progress form
> > THIS.SearchProgress(ldStart) && this is the form that displays date
> >
> > ENDDO
> >
> >
>
>
>



Relevant Pages