|
-
Jun 9th, 2001, 05:38 PM
#1
Thread Starter
PowerPoster
getting out of a loop
Hi guy I know that you can solve this
I am making an led flash through a parallel port now the code which I am using, it send "1" and then stop for some seconds and then again it sends "0" and then stops for some seconds. That is all in a loop like this
Code:
Do
PortOut 888, 1
delay
PortOut 888, 0
delay
Loop Until stopl = True
This delay function is this
Code:
For i = 1 To 1000000
Next i
now I have two command buttons, one is for flashing the led and the other one is for stoping it.
Whenever I press the stop button, it will say that
stopl = true
so the loop will stop
But the problem is that whenver the led starts flashing, my whole program is frozen and I cannot click anywhere.
I know that there is something wrong but i cannot figure it out
Please give me a solution!
Thanks
-
Jun 9th, 2001, 05:43 PM
#2
Put a DoEvents in your loop (the 'Do...Loop' one).
-
Jun 9th, 2001, 05:45 PM
#3
PowerPoster
You might like to try DoEvents in the For..Next loop as well.
-
Jun 9th, 2001, 05:57 PM
#4
I suppose the sleep API wouldn't quite work in the same way as the program would freeze...
-
Jun 9th, 2001, 08:01 PM
#5
Use Exit For or Exit Do to exit a loop.
-
Jun 9th, 2001, 08:13 PM
#6
_______
<?>
Code:
'Use a boolean variable to stop a For Next Loop
Option Explicit
Dim bGetOut As Boolean 'trigger to stop loop
Private Sub Command1_Click()
bGetOut = False 'reset if you want to start again
Dim myInt As Integer 'incremen
Do While Not bGetOut
Randomize 'Rnd Function
myInt = myInt + CInt(Rnd * 10) + 1 'create new caption
Me.Caption = myInt
DoEvents
Loop
End Sub
Private Sub Form_DblClick()
'dbl click the form to stop the loop
bGetOut = True
End Sub
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Jun 9th, 2001, 08:38 PM
#7
-
Jun 9th, 2001, 10:34 PM
#8
Thread Starter
PowerPoster
OK
DoEvents
That works now but there is another problem
I am creating a stepper motor controller which has a stepper motor and a LED.
-- When the stepper motor moves, I want to flash the led. To flash the LED, I need to first send a "1" and then a delay of some second, and then a "0".
-- When the motor is moving -- it is in a loop -- I want to flash the led.
--I have created a function for the delay that looks like this
Code:
For delaytime = 1 to 40000
Next
--Now If I put this code:
Code:
Do
(Here is all the code to rotate the motor in a loop which is too long so I did not put it here)
portn = PortIn(888)
Call PortOut(888, portn + 16)
delay
Call PortOut(888, portn + 0)
delay
Loop
(PortOut, PortIn are just two functions to send and retrieve a value to and from the parallel port. "16" is just the value which lights the led, and 0 turns the led off. I retrived the value from the parallel port first because I wanted the motor to keep rotating)
The problem is that when the delay is used, it stop the led flashing and also the stepper motor. I want the stepper motor to keep doing its work but the led should stop for the time which is given the loop.
If you dont understand anything then please ask me
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|