User Tools

Site Tools


k10:k10.5:k10.5.3:start

10.5.3 Stop

The STOP statement stops a program and wakes up the debugger as if there was a breakpoint in the current line. This command interrupts the program - nothing more happens.

10.5.3.1 Stop vs. Breakpoint

STOP is actually only relevant in debugging mode during program testing. Normally you develop programs in the IDE and can set breakpoints there. But there is a small, subtle difference: you can link STOP to a condition, while a breakpoint is firmly attached to a line. For example, if only the last pass in a loop control structure is of interest, you can write in the loop body:

If iCurrentIndex = iLastIndex Then Stop 

The program will be interrupted at most once if iCurrentIndex assumes a very special value in the loop. If, on the other hand, you set a line-bound breakpoint, the program stops in every iteration, which can become annoying.

10.5.3.2 Stop Event

The complex STOP EVENT statement is a stand-alone statement, has no relation to the above-mentioned stop and must be used in an event handler. It tells the interpreter that the (native) event that called the event handler is terminated.

The following three examples demonstrate the use of Stop Event:

Example 1

PUBLIC SUB TextBox1_KeyPress() 
  If Key.Text Not Like "[0-9]" Then STOP EVENT
END ' TextBox1_KeyPress() 
PUBLIC SUB TextBox1_KeyPress() 
 IF Instr("0123456789", Key.Text) = 0 THEN STOP EVENT 
END ' TextBox1_KeyPress() 

These often specified two procedures for the safe entry of digits from the interval[0-9] have the general disadvantage that you have no possibility to delete or correct incorrect entries directly via the keyboard or to navigate in the TextBox! However, it is still possible to mark erroneous numbers or number blocks with the mouse and overwrite them with the correct numbers.

A real alternative - by Charles Guerin and Benoît Minisini - accepts not only the digits 0… 9 as a secure entry, but also the six keys you need for necessary corrections and navigation in the TextBox:

Public Sub CheckInput(sAllowed As String)
  Dim iAllow As Integer = 0
 
  If Key.Code = Key.BackSpace Then iAllow = 1 
  If Key.Code = Key.Delete Then iAllow = 1  
  If Key.Code = Key.Left Then iAllow = 1 
  If Key.Code = Key.Right Then iAllow = 1
  If Key.Code = Key.End Then iAllow = 1 
  If Key.Code = Key.Home Then iAllow = 1
 
  If Key.Text And (InStr(sAllowed, Key.Text) > 0) Then iAllow = 1
 
' If an invalid key is pressed, the _KeyPress event is aborted.
  If iAllow = 0 Then STOP EVENT  
 
End ' CheckInput(sAllowed As String)
 
PUBLIC SUB TextBox1_KeyPress() 
  CheckInput("0123456789")
END ' TextBox1_KeyPress() 

As an extension, you can add the following lines to the procedure CheckInput (…) after' If Key. Code = Key. Home… '. With the Enter or Return key you accept the contents of the TextBox - if there is at least one character - and save it in the variable sInput:

If TextBox1.Text And (Key.Code = Key.Enter Or Key.Code = Key.Return) Then 
   iAllow = 1
   sInput = TextBox1.Text ' Print TextBox1.Text
Endif

Example 2

PUBLIC SUB MyObserver_Show() 
  Message.Info("The main window has already seen the light of the monitor!") 
  STOP EVENT  ' The MyObserver_Show event is canceled
END ' MyObserver_Show() 

Example 3

PUBLIC SUB Form_Close() 
  IF NOT ModulGlobal.AllowClose THEN 
     STOP EVENT ' The window remains open... the Form_Close_Event is canceled.
  ELSE 
     ME.Close 
  ENDIF 
END ' Form_Close() 

Download

Articles

Download

The website uses a temporary session cookie. This technically necessary cookie is deleted when the browser is closed. You can find information on cookies in our privacy policy.
k10/k10.5/k10.5.3/start.txt · Last modified: 23.09.2023 by honsek

Page Tools