DO...UNTIL hogging issue

Discuss whatever you want here--both QB and non-QB related. Anything from the DEF INT command to the meaning of life!

Moderators: Pete, Mods

Post Reply
kalc
Coder
Posts: 34
Joined: Thu Aug 18, 2005 1:26 am
Location: Tasmania, Australia

DO...UNTIL hogging issue

Post by kalc »

Code: Select all

'Clicking on box example
DIM x AS INTEGER, y AS INTEGER, button AS Integer
Screen 7

WindowTitle "Mouse clicking example"
Color 2,15
cls

For px = 50 To 70
 For py = 50 To 70
  PSet (px,py), 14
 Next
Next

Do
 GetMouse x, y,, button
 If button = 1 Then
  If x>50 And x<70 Then
   If y>50 And y<70 Then i = 1
  End If
 End If
Loop Until i = 1

Print "Press any key..."
   
Sleep
This is what happens with all DO...LOOP UNTIL elements, it is constantly checking for a certain occourence and uses all the CPU. How do you get around this?
I need a pen
Z!re
Veteran
Posts: 887
Joined: Wed Aug 04, 2004 11:15 am

Post by Z!re »

Sleep

use Sleep 1 to Sleep 20

Whatever suits you..

I usually use sleep 1
I have left this dump.
kalc
Coder
Posts: 34
Joined: Thu Aug 18, 2005 1:26 am
Location: Tasmania, Australia

Post by kalc »

But I want it wait for the user to click on the box.
I need a pen
Z!re
Veteran
Posts: 887
Joined: Wed Aug 04, 2004 11:15 am

Post by Z!re »

Code: Select all

'Clicking on box example
DIM x AS INTEGER, y AS INTEGER, button AS Integer
Screen 7

WindowTitle "Mouse clicking example"
Color 2,15
cls

For px = 50 To 70
 For py = 50 To 70
  PSet (px,py), 14
 Next
Next

Do
 GetMouse x, y,, button
 If button = 1 Then
  If x>50 And x<70 Then
   If y>50 And y<70 Then i = 1
  End If
 End If
 Sleep 1
Loop Until i = 1

Print "Press any key..."
   
Sleep 
Try it.. Sleep in FB uses millisecond accuracy, not seconds as in QB..

Sleep 1 means: wait for 1/1000th of a second..
I have left this dump.
kalc
Coder
Posts: 34
Joined: Thu Aug 18, 2005 1:26 am
Location: Tasmania, Australia

Post by kalc »

???! That is not what I'm asking. I know that SLEEP counts in milliseconds in FB, but I want to wait for the user to click on the box. Girls... wadda thay know? :lol:
I need a pen
guest

Post by guest »

kalc wrote:???! That is not what I'm asking. I know that SLEEP counts in milliseconds in FB, but I want to wait for the user to click on the box. Girls... wadda thay know? :lol:

i'd be careful she's libel to take that sword there and
lop your head off...
woot

Post by woot »

kalc wrote:???! That is not what I'm asking. I know that SLEEP counts in milliseconds in FB, but I want to wait for the user to click on the box. Girls... wadda thay know? :lol:

this is a great way to end up not getting any help at all
kalc
Coder
Posts: 34
Joined: Thu Aug 18, 2005 1:26 am
Location: Tasmania, Australia

Post by kalc »

'd be careful she's libel to take that sword there
OK, sorry Z!re, just couldn't help stating the obvious. No, seriously, sorry. But there is real iron in there: libel! God damn, so good... I might publish it! < That is kind of irony! :lol: :shock:
I need a pen
Z!re
Veteran
Posts: 887
Joined: Wed Aug 04, 2004 11:15 am

Post by Z!re »

*glares*
kalc wrote:This is what happens with all DO...LOOP UNTIL elements, it is constantly checking for a certain occourence and uses all the CPU. How do you get around this?
To solve the hogging issue, add the sleep 1
kalc wrote:That is not what I'm asking.
kalc wrote:I want to wait for the user to click on the box
Ok, so hogging isnt a problem then? Fine, your code works just fine, stfu.


Next time, before you even think about bashing me, try what I've said.
I have left this dump.
Seb McClouth

Post by Seb McClouth »

My advice: listen to Z!re, she knows what she's talking about. Now I think about it... we should call here lady Z!re... hehehe

grtz
Seb
kalc
Coder
Posts: 34
Joined: Thu Aug 18, 2005 1:26 am
Location: Tasmania, Australia

Post by kalc »

OK Z!re, I am very sorry. I thoought you ws just telling me about the diferrences between FB and QB with Sleep. This has solved my problem, and a problem that occurs in so many of my programs. Thank you Z!re :!:
I need a pen
Z!re
Veteran
Posts: 887
Joined: Wed Aug 04, 2004 11:15 am

Post by Z!re »

No problem.. good luck with your coding..
I have left this dump.
Post Reply