[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Ongoing vb 6 timer problem

Posted on 2014-01-27
8
Medium Priority
?
255 Views
Last Modified: 2014-01-30
I had a previous qustion about a timer not working correctly http://www.experts-exchange.com/Programming/Languages/Visual_Basic/Q_28347565.html#a39810418
 and found a fix by adding both the sound and label
rotation into the timer. my fix has found another problem where the timer is called from within a loop.
The program has an auto-play feature where 20 numbers are produced randomilly to an 80 number msflexgrid.
with each loop 20 numbers are randomilly produced and the results are added up if a win
It works correctly if no win, but the win is where the problem arrises
The problem is the timer only fires one time and returns to the loop
example:
 mEndNum = 4
the labes should increment 4 times, but they only do one time and return to the loop
if label lblCredit.Caption = $4.00 and mCurrencyWon = .25 then
$4.25 it stops here and returns to the loop
$4.50
$4.75
$5.00 should stop here

Private Sub Timer1_Timer()
'Dim Counter As Integer
Dim lblcreditcurrency As Currency

   If mbStartSound <> True Then
   sndData = LoadResData("ADDINGWINNINGS", "SOUND")
        sndPlaySound sndData(0), SND_LOOP Or SND_ASYNC Or SND_MEMORY
   End If         
        If miCnt <= mEndNum Then
            lblWinThisRun.Caption = lblWinThisRun.Caption + 1
          If mCreditMode = 1 Then
'          lblcreditcurrency = GetPriceByBetMode(mBetMode)
            lblCredit.Caption = CCur(lblCredit.Caption) + mCurrencyWon 'checked out
            lblCredit.Caption = Format(lblCredit.Caption, "currency")
           
            miCnt = miCnt + 1
            
          Else
            lblCredit.Caption = Val(lblCredit.Caption) + 1
            miCnt = miCnt + 1
          End If
          mbStartSound = True
        Else
            'Counter = 1
            Timer1.Enabled = False
            'Stop the Sound
            sndPlaySound ByVal 0, 0
            mbStartSound = False
        End If

Open in new window

0
Comment
Question by:isnoend2001
  • 5
  • 3
8 Comments
 
LVL 50

Accepted Solution

by:
Martin Liss earned 2000 total points
ID: 39814000
If you put a breakpoint on line 9 is miCnt <= mEndNum? If not then line 25 will turn the timer off.
0
 

Author Closing Comment

by:isnoend2001
ID: 39815048
Thanks MartinLiss

Got it to work by replacing (if) with a do loop
'If miCnt <= mEndNum Then

   Do While bFinished = False
    do sound and rotate labels
miCnt= miCnt + 1

 If miCnt > mEndNum Then          
            bFinished = True
            DoEvents
           End If
    Loop
0
 
LVL 50

Expert Comment

by:Martin Liss
ID: 39815744
You're welcome.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:isnoend2001
ID: 39821780
hi MartinLiss
Thought I had the loop timer corrected, but no
Did a little test with just a form and timer

With a loop doing 12 runs
with each run the label rotates from 0 to 20
the timer returns after only 1 label rotation
and does not do any of the remaing loops
Is there a problem with a timer in a loop not finishing the loop before returning ?
0
 
LVL 50

Expert Comment

by:Martin Liss
ID: 39821795
Can you zip up and attach your test project?
0
 

Author Comment

by:isnoend2001
ID: 39822159
This for the 80 number keno game. the loop is for the auto play and the 12 free bonus games
where the user does not have to repeatedly click the start button.
Everything works good until i put the timer label rotation into a loop
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month18 days, 13 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question