Solved

Ongoing vb 6 timer problem

Posted on 2014-01-27
8
234 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 47

Accepted Solution

by:
Martin Liss earned 500 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 47

Expert Comment

by:Martin Liss
ID: 39815744
You're welcome.
0
Independent Software Vendors: 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 47

Expert Comment

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

Author Comment

by:isnoend2001
ID: 39822112
0
 

Author Comment

by:isnoend2001
ID: 39822132
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

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!

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

749 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