Solved

Ongoing vb 6 timer problem

Posted on 2014-01-27
8
232 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 46

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 46

Expert Comment

by:Martin Liss
ID: 39815744
You're welcome.
0
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 

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 46

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

777 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