Solved

Ongoing vb 6 timer problem

Posted on 2014-01-27
8
229 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 45

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 45

Expert Comment

by:Martin Liss
ID: 39815744
You're welcome.
0
 

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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 45

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
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…

707 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now