While/Wend Problem

BlitzPlus Forums/BlitzPlus Beginners Area/While/Wend Problem

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

;CONSTANTS 
Const WINDOW_WIDTH=500
Const WINDOW_HEIGHT=400
Const WINDOW_FLAGS=15
;EVENT CONSTANTS
Const X_HIT=$803;The 'X' was hit
Const GADGET_USED=$401;A gadget was used
;VARIABLES
DESKTOP_WIDTH=ClientWidth(Desktop())
DESKTOP_HEIGHT=ClientHeight(Desktop())
;This function is to get the program started
Function Start()
Main=CreateWindow("START UP GUI TEST #1",DESKTOP_WIDTH,DESKTOP_HEIGHT,WINDOW_WIDTH,WINDOW_HEIGHT,Main,15)
Button=CreateButton("CREATE",WINDOW_WIDTH-300,WINDOW_HEIGHT-300,100,100,Main,1)
Ev=WaitEvent()
Es=EventSource()
While Not KeyDown(1)
Select Es
Case Main:
Blah=Confirm("Positive?",True)
If Ev=$803 
If Blah=1 Then
End 
If Blah<>1 Then 
Notify("Find out what you"+Chr(10)+"want next time")
EndIf 
EndIf 
EndIf
End Select 
Wend 
End Function 
Start()
End 

My problem is that the error 'Wend without While' pops
up, Why?