Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Stop table insertions
Message
 
 
À
28/11/2000 16:02:02
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00446434
Message ID:
00446551
Vues:
8
>I have created a test program that is basically doing a numbers crunch, inserting multiple records into two different tables one after another. I want it to continue inserting records until the users tells it to stop. Right now I have it set up to stop when the user hits the ESC key (by putting all of my code in a Do While loop: DO WHILE(inkey() <> 27)). But, when the user hits ESC instead I am getting an error which says ***INTERRUPTED***. It doesn't finish going through the code, it just stops dead in its tracks. Can anyone tell me a good way to stop the insertions without getting the error message?

Hi Joe,

I want to show you the approach, I use for this. I don't like using inkey(), because it slows down the perfomance. See, if code bellow would help you.
* support user Escapes for interrupting the main loop
prevonesc = on('escape')                    &amp;&amp; save previous Escape handler
prevescape = set('escape')                    &amp;&amp; previous Escape enablement state
set escape on                                   &amp;&amp; enable escape handling
halt = .f.                                        &amp;&amp; allow loop to run until this flag is toggled
on escape halt = .t.                         &amp;&amp; force immediate termination if user escapes
store 0 to lnTally, lnCount, lnBadAPN

lnReccount=reccount()

do case
  case lnReccount&lt;100 &amp;&amp; Very rare case
    lnUpdateNumber=1
  case between(lnReccount,100,100000)
    lnUpdateNumber=100
  case lnReccount&gt;100000
    lnUpdateNumber=val('1'+replicate('0',len(transform(lnReccount))-3))
endcase        

* assemble fixed portion of status bar message outside of loop, for speed
msgtail = "/" + transform(lnReccount) + ".  Wait or press Esc to cancel ..."
set message to
*--- instantiate thermometer bar class....
lotherm = newobject("thermometer", "wg","","Progress for APN calculating...",lnReccount)
lotherm.show()

scan  
     lnCount=lnCount+1

* check for user Escape
     if m.halt                                   &amp;&amp; user escaped
          exit                                   &amp;&amp; fall out of loop
     endif

** Update thermometr
     if mod(lnCount,lnUpdateNumber) = 0
          set message to 'Record # '+alltrim(str(lnCount))+m.msgtail
          lotherm.update(lnCount)
     endif
If it's not broken, fix it until it is.


My Blog
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform