Page 1 of 1
Posted: Sun May 12, 2002 4:17 pm
by BackupUser
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!
Posted: Sun May 12, 2002 6:24 pm
by BackupUser
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:
Code: Select all
InitKeyboard()
While pushed = 0
ExamineKeyboard()
pushed = KeyboardPushed(#PB_Key_Space)
; Do something
Wend
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
Posted: Tue May 14, 2002 8:28 am
by BackupUser
Restored from previous forum. Originally posted by willinyork.
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
Wend
I hope this is what you are looking for.
Hi Merendo
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!
Posted: Tue May 14, 2002 9:39 am
by BackupUser
Restored from previous forum. Originally posted by freak.
[quote]What I want is the while x0.
Hope this is what you mean...
Timo
--
A debugged program is one for which you have not yet found the conditions that make it fail.
Posted: Tue May 14, 2002 3:43 pm
by BackupUser
Restored from previous forum. Originally posted by willinyork.
What I want is the while x0.
Still can't get it to work...

I have tried it using the space bar example above, and also by doing it with a mouse. Any ideas?
Posted: Tue May 14, 2002 11:34 pm
by BackupUser
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
Posted: Wed May 15, 2002 10:20 am
by BackupUser
Restored from previous forum. Originally posted by willinyork.
Many thanks everyone for your help! After a little (well, a lot!) of fiddling about and learning, we've got it fixed
Many thanks!