Restored from previous forum. Originally posted by willinyork.
Hi there
In my program I have a while wend loop going. Is it possible to have a "stop" button which you could click on while the loop is in progress which would stop the loop? Or even the ability to press a key? something like:
while spacebar is not pressed
blah blah
wend
thanks for your help!
"stop" button
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by merendo.
I don´t entirely understand what you mean. Do you mean, that the loop shall stop, when the user hits a key? Try this:
I hope this is what you are looking for.
Have a nice day, merendo
We always need to hear both sides of the story (by Phil Collins)
Edited by - merendo on 12 May 2002 19:25:42
Edited by - merendo on 12 May 2002 19:27:15
I don´t entirely understand what you mean. Do you mean, that the loop shall stop, when the user hits a key? Try this:
Code: Select all
InitKeyboard()
While pushed = 0
ExamineKeyboard()
pushed = KeyboardPushed(#PB_Key_Space)
; Do something
WendHave a nice day, merendo
We always need to hear both sides of the story (by Phil Collins)
Edited by - merendo on 12 May 2002 19:25:42
Edited by - merendo on 12 May 2002 19:27:15
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by willinyork.
I see that what you have typed would be great for me, but I can't get it to work. I have some code like this:
Case 150 ; Play Button Clicked
gosub playbutton pressed
playbuttonpressed:
initkeyboard()
pressed=0
Disablegadget(playbutton etc)
while x0
return
endif
playsound 2 etc
examinekeyboard()
pushed = KeyboardPushed(#PB_Key_Space)
if pushed0
return
endif
playsound 3 etc
examinekeyboard()
pushed = KeyboardPushed(#PB_Key_Space)
if pushed0
return
endif
x=x+1
wend
return
What I want is the while x<y wend loop to work (it does work), but also have the option of being able to stop the loop and return from the subroutine without having to wait for x to be as big as y. I want to be able to do this by either pressing a key, or click a mouse button (if it is easier to code)
Thank you for your help!
Hi MerendoI don´t entirely understand what you mean. Do you mean, that the loop shall stop, when the user hits a key? Try this:
I hope this is what you are looking for.Code: Select all
InitKeyboard() While pushed = 0 ExamineKeyboard() pushed = KeyboardPushed(#PB_Key_Space) ; Do something Wend
I see that what you have typed would be great for me, but I can't get it to work. I have some code like this:
Case 150 ; Play Button Clicked
gosub playbutton pressed
playbuttonpressed:
initkeyboard()
pressed=0
Disablegadget(playbutton etc)
while x0
return
endif
playsound 2 etc
examinekeyboard()
pushed = KeyboardPushed(#PB_Key_Space)
if pushed0
return
endif
playsound 3 etc
examinekeyboard()
pushed = KeyboardPushed(#PB_Key_Space)
if pushed0
return
endif
x=x+1
wend
return
What I want is the while x<y wend loop to work (it does work), but also have the option of being able to stop the loop and return from the subroutine without having to wait for x to be as big as y. I want to be able to do this by either pressing a key, or click a mouse button (if it is easier to code)
Thank you for your help!
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by scurrier.
try this maybe this is what your looking for
#WindowWidth = 640
#WindowHeight = 480
Content$="test"
If OpenWindow(0, 100, 120, #WindowWidth, #WindowHeight, #PB_Window_SystemMenu | #PB_Window_MinimizeGadget, "PureBasic - Gadget Demonstration")
If CreateGadgetList(WindowID())
Top = 10
GadgetHeight = 24
StringGadget(0, 10, 50, 60, 20, Content$)
ButtonGadget(1, 100, 50, 60, 20, "Stop Loop")
EndIf
EndIf
q=0
Repeat
Event = WindowEvent()
x=x+1
If x>10000
x=1
EndIf
SetGadgetText(0, Str(x))
Delay(100)
result = EventGadgetID()
If result=1
q=1
EndIf
Until q=1
End
try this maybe this is what your looking for
#WindowWidth = 640
#WindowHeight = 480
Content$="test"
If OpenWindow(0, 100, 120, #WindowWidth, #WindowHeight, #PB_Window_SystemMenu | #PB_Window_MinimizeGadget, "PureBasic - Gadget Demonstration")
If CreateGadgetList(WindowID())
Top = 10
GadgetHeight = 24
StringGadget(0, 10, 50, 60, 20, Content$)
ButtonGadget(1, 100, 50, 60, 20, "Stop Loop")
EndIf
EndIf
q=0
Repeat
Event = WindowEvent()
x=x+1
If x>10000
x=1
EndIf
SetGadgetText(0, Str(x))
Delay(100)
result = EventGadgetID()
If result=1
q=1
EndIf
Until q=1
End
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm