More VB help.

GEC: Discuss gaming, computers and electronics and venture into the bizarre world of STGODs.

Moderator: Thanas

Post Reply
User avatar
GoldenFalcon
Jedi Knight
Posts: 551
Joined: 2004-03-01 11:08pm
Location: Busy practicing with a bokken, come near me and I'll whack you with it.

More VB help.

Post by GoldenFalcon »

Alrighty, this time I'm coding a simple stopwatch.

Question 1:

I placed a timer "timStopwatch" in the form "frmStopwatch". Now, the stopwatch code is contained in a module "modStopwatch". All the variables listed have been declared in Sub Main().

Stopwatch code:

Code: Select all

Public Function StopwatchRun()
    If Hours = 99 Then
    frmStopwatch.timStopwatch.Enabled = False
    Message = MsgBox("The timer has reached its limit of 99 hours.  The stopwatch has been shut down.", vbOKOnly + vbExclamation, "Warning")
    Else
        If Minutes = 60 Then
        Hours = Hours + 1
        Minutes = 0
        Else
            If Seconds = 60 Then
            Minutes = Minutes + 1
            Seconds = 0
            Else
                If Milliseconds = 60 Then
                Seconds = Seconds + 1
                Milliseconds = 0
                Else
                Milliseconds = Milliseconds + 1
                End If
            End If
        End If
    End If
    StopwatchRun = Milliseconds
End Function
As you can see it's a whole bunch of if statements which alters the time. The time is shown in a label "lblTime" at the top of the form. And yes I'm aware that only Milliseconds are being shown, haven't changed it to include everything yet. However, even when it shows Seconds it is different as you will see.

Now, for the timer code:

Code: Select all

Private Sub timStopwatch_Timer()
    lblTime.Caption = StopwatchRun()
End Sub
There are buttons in the form which enable/disable timStopwatch. Now here's the problem: I enable timStopwatch and it completely ignores milliseconds above 1. Even when I press my "reset" button when the timer is still on, it resets to zero and returns back to 1, but still sticks to 1. Why's this? :?

Question 2:

How do I make it so lblTime shows:

Hours : Minutes : Seconds : Milliseconds

In that orders? Hours, Minutes, Seconds, and Milliseconds are all variables, but the colons aren't. I thought of:

Code: Select all

lblTime.Caption = Hours, ":", Minutes, ":", Seconds, ":", Milliseconds
But as I first thought it didn't work well. How do I combine variables with normal text?

Thanks if you help...
Babylon 5: In the Beginning quote:

General Lefcourt: "My people can handle themselves. We took care of the Dilgar. We can take care of the Minbari."
Londo Mollari: "Ahh, arrogance and stupidity all in the same package. How efficient of you."


Coming soon: Firebird Productions
Super-Gagme
Little Stalker Boy
Posts: 1282
Joined: 2002-10-26 07:20am
Location: Lincoln, UK
Contact:

Post by Super-Gagme »

1 - Your function has no type, try setting it to the type that the variable Milliseconds is returning to it. If that doesn't work, I'll exam in more detail :p

2- To assign variables to a string like the Caption of a label try this.


Code: Select all

lblTime.Caption = Hours & ":" & Minutes & ":" & Seconds & ":" & Milliseconds
History? I love history! First, something happens, then, something else happens! It's so sequential!! Thank you first guy, for writing things down!

evilcat4000: I dont spam

Cairbur: The Bible can, and has, been used to prove anything and everything (practically!)
StarshipTitanic: Prove it.
User avatar
GoldenFalcon
Jedi Knight
Posts: 551
Joined: 2004-03-01 11:08pm
Location: Busy practicing with a bokken, come near me and I'll whack you with it.

Post by GoldenFalcon »

Thanks, it worked. :)
Babylon 5: In the Beginning quote:

General Lefcourt: "My people can handle themselves. We took care of the Dilgar. We can take care of the Minbari."
Londo Mollari: "Ahh, arrogance and stupidity all in the same package. How efficient of you."


Coming soon: Firebird Productions
Post Reply