|
-
Feb 7th, 2014, 04:49 PM
#1
Thread Starter
PowerPoster
[RESOLVED] Exit a do loop
I have an 80 number keno game that win run if a win 2 labels are rotated and a sound plays the amount of the win
I am trying to make the labels update instantly if the form is click and skip the label rotation
the mbSpeedTimer is ignored when the form is clicked
The form click sets mbSpeedTimer to true
Code:
Private Sub Form_Click()
mbSpeedTimer = True 'skip label rotation just increase winnings mbWinInProgress = True
Private Sub Timer1_Timer()
Dim bFinished As Boolean
Dim lblcreditcurrency As Currency
If mbSpeedTimer Then
FastAddWins
Exit Sub
End If
If mbStartSound = False Then
mbytData = LoadResData("tick", "SOUND")
sndPlaySound mbytData(0), SND_LOOP Or SND_ASYNC Or SND_MEMORY
End If
Do While bFinished = False
If mbSpeedTimer Then 'speed up win if user clicked form or images
sndPlaySound ByVal 0, 0 'Stop the Sound
Timer1.Enabled = False
Exit Do
Call FastAddWins ' call the sub to total labels instantly
Exit Sub
End If
If mbSpeedTimer = False Then
Sleep 90 ' added this to slow labels for some reason changing the interval didn't work
Else
Exit Do
End If
lblWinThisRun.Caption = lblWinThisRun.Caption + 1
If mintCreditMode = 1 Then '
lblCredit.Caption = CCur(lblCredit.Caption) + mcurCurrencyWon 'checked out
lblCredit.Caption = Format(lblCredit.Caption, "currency")
mlngCnt = mlngCnt + 1
Else
lblCredit.Caption = Val(lblCredit.Caption) + 1
mlngCnt = mlngCnt + 1
End If
If mlngCnt > mlngEndNum Then
WaitMessage ' don't know if this is needed or not
bFinished = True
DoEvents
End If
Loop
mbStartSound = True
Timer1.Enabled = False
sndPlaySound ByVal 0, 0 'Stop the Sound
mbStartSound = False
mbWaitforWinToFinish = False
mbRunInProgress = False
End Sub
Waiting for a full featured smart phone with out marrying a provider
Go Android
Go raiders 
-
Feb 7th, 2014, 05:40 PM
#2
Re: Exit a do loop
I think this part is buggy
1-
Code:
If mbSpeedTimer Then 'speed up win if user clicked form or images
sndPlaySound ByVal 0, 0 'Stop the Sound
Timer1.Enabled = False
Exit Do
Call FastAddWins ' call the sub to total labels instantly
Exit Sub
End If
Call FastAddWins and Exit Sub aren't executed because they comes after Exit Do. Exit Sub is enough.
If you want to execute the lines after Loop, try to rebuild it like this
Code:
Do While bFinished = False
If mbSpeedTimer Then 'speed up win if user clicked form or images
sndPlaySound ByVal(0, 0) 'Stop the Sound
Timer1.Enabled = False
Call FastAddWins() ' call the sub to total labels instantly
Exit Do
Else
If mbSpeedTimer = False Then
Sleep 90 ' added this to slow labels for some reason changing the interval didn't work
Else
Exit Do
End If
lblWinThisRun.Caption = lblWinThisRun.Caption + 1
If mintCreditMode = 1 Then '
lblCredit.Caption = CCur(lblCredit.Caption) + mcurCurrencyWon 'checked out
lblCredit.Caption = Format(lblCredit.Caption, "currency")
mlngCnt = mlngCnt + 1
Else
lblCredit.Caption = Val(lblCredit.Caption) + 1
mlngCnt = mlngCnt + 1
End If
If mlngCnt > mlngEndNum Then
WaitMessage() ' don't know if this is needed or not
bFinished = True
DoEvents()
End If
End If
Loop
-
Feb 7th, 2014, 06:03 PM
#3
Re: Exit a do loop
Putting a loop inside a timer doesn't sound like a good idea to me but if you are going to do that and you want to pick up the form click you will need a doevents inside your loop so the click will be processed. You do have a doevents in there now but it is inside an if statement and will only be called when mlngCnt > mlngEndNum. It appears by then it is too late.
-
Feb 7th, 2014, 06:09 PM
#4
Thread Starter
PowerPoster
Re: Exit a do loop
 Originally Posted by 4x2y
I think this part is buggy
1-
Code:
If mbSpeedTimer Then 'speed up win if user clicked form or images
sndPlaySound ByVal 0, 0 'Stop the Sound
Timer1.Enabled = False
Exit Do
Call FastAddWins ' call the sub to total labels instantly
Exit Sub
End If
Call FastAddWins and Exit Sub aren't executed because they comes after Exit Do. Exit Sub is enough.
If you want to execute the lines after Loop, try to rebuild it like this
Code:
Do While bFinished = False
If mbSpeedTimer Then 'speed up win if user clicked form or images
sndPlaySound ByVal(0, 0) 'Stop the Sound
Timer1.Enabled = False
Call FastAddWins() ' call the sub to total labels instantly
Exit Do
Else
If mbSpeedTimer = False Then
Sleep 90 ' added this to slow labels for some reason changing the interval didn't work
Else
Exit Do
End If
lblWinThisRun.Caption = lblWinThisRun.Caption + 1
If mintCreditMode = 1 Then '
lblCredit.Caption = CCur(lblCredit.Caption) + mcurCurrencyWon 'checked out
lblCredit.Caption = Format(lblCredit.Caption, "currency")
mlngCnt = mlngCnt + 1
Else
lblCredit.Caption = Val(lblCredit.Caption) + 1
mlngCnt = mlngCnt + 1
End If
If mlngCnt > mlngEndNum Then
WaitMessage() ' don't know if this is needed or not
bFinished = True
DoEvents()
End If
End If
Loop
Thanks
I put a break here
sndPlaySound ByVal 0, 0 'Stop the Sound
And it is not hit when the form is clicked
Waiting for a full featured smart phone with out marrying a provider
Go Android
Go raiders 
-
Feb 7th, 2014, 06:15 PM
#5
Re: Exit a do loop
 Originally Posted by isnoend07
it is not hit when the form is clicked
You must ensure that DoEvents executed frequently
-
Feb 7th, 2014, 06:28 PM
#6
Thread Starter
PowerPoster
Re: Exit a do loop
 Originally Posted by MarkT
Putting a loop inside a timer doesn't sound like a good idea to me but if you are going to do that and you want to pick up the form click you will need a doevents inside your loop so the click will be processed. You do have a doevents in there now but it is inside an if statement and will only be called when mlngCnt > mlngEndNum. It appears by then it is too late.
Thanks
adding that doevents now sees the form click. Don't remember why i added the do loop inside the timer, but it fixed some issue i was having
Waiting for a full featured smart phone with out marrying a provider
Go Android
Go raiders 
-
Feb 7th, 2014, 06:47 PM
#7
Thread Starter
PowerPoster
Re: Exit a do loop
 Originally Posted by 4x2y
You must ensure that DoEvents executed frequently
What do you mean frequently ?
I have tried using DoEvents many times for different issues, but it seemed to never work.
This is the second time in the last week i found it useful.
The other to pause a program until a boolen was false
If mbWaitforWinToFinish = True Then
Do Until mbWaitforWinToFinish = False
DoEvents
Loop
End If
Waiting for a full featured smart phone with out marrying a provider
Go Android
Go raiders 
-
Feb 7th, 2014, 07:15 PM
#8
Re: Exit a do loop
 Originally Posted by isnoend07
What do you mean frequently ?
Usually when i have loop that can iterate too much, i do DoEvents each 100 or 1000 according to how many iteration the loop will run.
instead of
Code:
Do
DoEvents
' other code
Loop Until condition
i do
Code:
Dim c As Long
Do
c = c + 1
If c >= 100 Then
c = 0
DoEvents
End If
' other code
Loop Until condition
This enhance performance too much.
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
|