Change Colors, along with start a second timer

I have this script below, and I actually have 2 questions about it. First.... Where is says "HERE" is clicked how do i get another timer going to change the EndTime accordenly dpending on how long the Timer (main one) is "Paused"... Also I can NOT figure out how to change the font color when there is 10 min left, and 3 min left.... I tried: Display.ForeGround = vbRed In a IF THEN statement, but i doesn seem to work....

Dim ClockRunning As Byte
Dim PauseState As Byte
Dim ViewOptions As Byte
Dim Counter As Long
Private Sub Form_Unload(Cancel As Integer)
Dim i As Integer
For i = 0 To Forms.Count - 1
     Unload Forms(i)
Next i
End
End Sub

Private Sub Options_Click()
    If ViewOptions = Flase Then
        RoundClock.Height = 6810
        RoundClock.Width = 8115
        ViewOptions = True
    Else
        RoundClock.Height = 3330
        RoundClock.Width = 3360
        ViewOptions = False
    End If
End Sub
Private Sub Set40_Click()
    MinSet.Text = "40"
End Sub
Private Sub Set45_Click()
    MinSet.Text = "45"
End Sub
Private Sub Set50_Click()
    MinSet.Text = "50"
End Sub
Private Sub Start_Click()
    If ClockRunning = False Then
        If PauseState = False Then
            Counter = Val(MinSet.Text) * 60
            Timer.Interval = 1000
            Timer.Enabled = True
            StartTime.Text = DatePart("h", Time) & ":" & DatePart("n", Time) & ":" & DatePart("s", Time)
            EndTime.Text = DatePart("h", DateAdd("n", Val(MinSet.Text), Time)) & ":" & DatePart("n", DateAdd("n", Val(MinSet.Text), Time)) & ":" & DatePart("s", DateAdd("n", Val(MinSet.Text), Time))
            ClockIMG.Visible = True
            Display.Show
            Start.Caption = "Pause"
            ClockRunning = True
            MinSet.Enabled = False
            MinSet.Locked = True
        Else
            Timer.Enabled = True
            PauseState = False
            ClockRunning = True
            Start.Caption = "Pause"
        End If
    Else
       "<<<<<<<<<<<HERE>>>>>>>>>>>>>>>"
        Start.Caption = "Resume"
        Timer.Enabled = False
        ClockRunning = False
        PauseState = True
    End If
       
End Sub
Private Sub Stop_Click()
    StartTime.Text = ""
    EndTime.Text = ""
    MinSet.Text = ""
    MinLeft.Text = ""
    Timer.Enabled = False
    ClockIMG.Visible = False
    ClockRunning = False
    PauseState = False
    Start.Caption = "Start"
    Display.Cls
    MinSet.Enabled = True
    MinSet.Locked = Flase
End Sub
Private Sub Timer_Timer()
Dim Msg As String
Dim MsgLeft As String
    Msg = Counter \ 60 & ":" & Counter Mod 60
    MsgLeft = Counter \ 60
    If Not Display.Visible Or Counter <= 0 Then
        Display.CurrentX = (Display.ScaleWidth - Display.TextWidth(Msg)) / 2
        Display.CurrentY = (Display.ScaleHeight - Display.TextHeight(Msg)) / 2
        Display.Print "Times Up"
        Timer.Enabled = False
        ClockIMG.Visible = False
        ClockRunning = False
        PauseState = False
        Display.ForeColor = vbWhite
        Exit Sub
    End If
    Display.Cls
    Display.CurrentX = (Display.ScaleWidth - Display.TextWidth(Msg)) / 2
    Display.CurrentY = (Display.ScaleHeight - Display.TextHeight(Msg)) / 2
    Display.Print Msg
    MinLeft.Text = MsgLeft
    Counter = Counter - 1
End Sub
Gunit2507Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

GPrentice00Commented:

First, let me recommend that you use Option Explicit in each of your forms and modules, so that you explicitly define each variable and object in use – you’re already doing that, that’s good, but the Option Explicit also goes a step beyond forcing you to specify the variables, it helps with simplistic argument assignments as well.  The reason I suggest, is that you have some typos in your property assignments:
....
  If ViewOptions = Flase Then        
....
  MinSet.Locked = Flase


Without option explicit, flase is just a variable with no value; with it, the compiler detects that you don’t have a variable called flase, and errors.  While in this program, it causes no problems because "flase" and "false" both have the same value (zero), the argument can not be said for mistyping ‘true’ for object.property = ture….
GPrentice00Commented:

It took a bit of effort to reconstruct a working project from your code, and not all items there are clear, such as the “Options” and “RoundClock” things, but they don’t appear to have any influence on the functionality questions you have, and were not necessary to build a working project shell...

While this code is a very odd way of pulling off the job, it does work thus I shall just modify the core of it, preserving the code structure you have as much as possible rather than offer 300 different ways to do the same job - aiming to give you something to reverse-engineer for your own purposes later primarily.

First, the timer event needs a major overhauling (mostly in rearrangment, thus easier to repost in entirety) in order to comply with your wishes, and in here, you can see how commands are moved around.  I’ve also shown how and where to put in the conditions to change your text color depending on time remaining, and ‘prettied’ the time display message from 3:9 to 3:09 etc.

As for the second part of the problem – another timer part where you say “===here===” will be in my next comment.



Private Sub Timer_Timer()
    Dim Msg As String
    Dim MsgLeft As String
    Msg = Counter \ 60 & ":" & Format$(Counter Mod 60, "00")   'to show :09 instead of :9
    MsgLeft = Counter \ 60
    If Not Display.Visible Or Counter <= 0 Then
        Display.Cls      'must clear out the 0:01 counter display here
        Display.ForeColor = vbWhite  'must set the color before printing output
        ' make textposition based on the "times up" message that WILL be put there)
        Display.CurrentX = (Display.ScaleWidth - Display.TextWidth("Times Up")) / 2
        Display.CurrentY = (Display.ScaleHeight - Display.TextHeight("Times Up")) / 2
        Display.Print "Times Up"
        Timer.Enabled = False
        clockimg.Visible = False
        ClockRunning = False
        PauseState = False        
        Exit Sub
    End If
    Display.Cls
    ' change the color for different times by setting the conditions here... This does red text for under 3 minutes, and yellow for equal to and less than 1 minute
    If Counter < (3 * 60) Then
        Display.ForeColor = vbRed
        If Counter <= (1 * 60) Then
            Display.ForeColor = vbYellow
        End If
    End If
    Display.CurrentX = (Display.ScaleWidth - Display.TextWidth(Msg)) / 2
    Display.CurrentY = (Display.ScaleHeight - Display.TextHeight(Msg)) / 2
    Display.Print Msg
    minLeft.Text = MsgLeft    
    Counter = Counter - 1
End Sub
GPrentice00Commented:

To simplify your string construction (and use less computations as well), use the string formatting features and avoid breaking up the times into parts, reducing the two strings here:
            startTime.Text = DatePart("h", Time) & ":" & DatePart("n", Time) & ":" & DatePart("s", Time)
            endtime.Text = DatePart("h", DateAdd("n", Val(MinSet.Text), Time)) & ":" & DatePart("n", DateAdd("n", Val(MinSet.Text), Time)) & ":" & DatePart("s", DateAdd("n", Val(MinSet.Text), Time))

to much simplier
           startTime.Text = Format$(Time, "hh:mm:ss")            
            endtime.Text = Format$(DateAdd("n", Val(MinSet.Text), Time), "hh:mm:ss")

the dateadd function with adding minutes or seconds will also bump the time to the correct 24h display going past midnight….

============================

With that change in mind, add a second timer to the form, called TimerDuringPause, with interval of 1000 and disabled at design time.

Here is the code for its firing event:
Private Sub TimerDuringPause_Timer()
‘   Increase the displayed end-time time by 1 second and redisplay in time format
‘  This gets and redisplays directly from the form display, so it could be improved upon
    Dim TimeEndedNew As Date
    TimeEndedNew = DateAdd("s", 1, CDate(endtime.Text))
    endtime.Text = Format(TimeEndedNew, "hh:mm:ss")
End Sub

Now, modifying your start/pause/resume button code to reflect these changes:
Private Sub Start_Click()
' clockrunning indicates process underway
    If ClockRunning = False Then
        If PauseState = False Then
            Counter = Val(MinSet.Text) * 60
            Timer.Interval = 1000
            Timer.Enabled = True
      ‘simplify display construct here…
            startTime.Text = Format$(Time, "00:00:00")  
            endtime.Text = Format$(DateAdd("n", Val(MinSet.Text), Time), "hh:mm:ss")
            clockimg.Visible = True
            Display.Show
            start.Caption = "Pause"
            ClockRunning = True
            MinSet.Enabled = False
            MinSet.Locked = True
        Else
            Debug.Print "I don’t believe I’ll ever hit this condition"
            Timer.Enabled = True
            PauseState = False
            ClockRunning = True
            start.Caption = "Pause title, being changed from what?"
        End If
    Else ' clock is underway, button hit = pausing or unpausing clock
'       "<<<<<<<<<<<HERE>>>>>>>>>>>>>>>"
        If PauseState = True Then ' user pressed 'pause' button
            start.Caption = "Pause"
            PauseState = False
            Timer.Enabled = True
            TimerDuringPause.Enabled = False
        Else 'user pressed 'resume' button
            start.Caption = "Resume"
            PauseState = True
            Timer.Enabled = False
            TimerDuringPause.Enabled = True
        End If
       
    End If
       
End Sub

' at this point, you'll want to put code in to disable and enable various buttons, and perhaps when the STOP button is pressed, kill the second timer if it too is running, or kill the stop button when you pause, I dunno...


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.