Question:
Help In VB Please!!!!!!!!!!!!!!!!!?
anonymous
2009-01-29 16:11:51 UTC
Ok i have

1Lable >> I want the lable to show my countdown timer
1Timer
1Button

Ok i got a timer in this format Label2.Text = m + ":" + s

But i still can get the timer to start from 3 mins and count down to 0

Here is my full code

Public Class Form1
Dim m As String
Dim s As String

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
s = s - 1

If s = 60 Then
s = 0
m = m + 1
End If
Label2.Text = m + ":" + s
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Timer1.Interval = 1000
Timer1.Enabled = True
End Sub
End Class

What i want is to start the timer at 3:00 and have it countdown to 0:00

Please give answer in detail as im kinda new in vb
Three answers:
anonymous
2009-01-29 16:44:00 UTC
You can't get it to start at a certain time. Timer function are define to just go of at certain intervals like you've set. The way to do want you want to do is to initialize an internal counter and then reduce it's value every time your timer goes off.



Add a variable called secondsRemaining and in the click handler initialize it to 3 * 60 - since you're interval is 1000 (1 second) then it is best to use total seconds.



When the timer goes off decrement secondsRemaining by 1. WHen it gets to 0 you are done.



Now, how to display 2:02. If you use the format function you can get the accuracy you want.



Try Format (value, #.##) which will display a value giving 2 decimal points of accuracy.
anonymous
2016-11-13 06:02:06 UTC
it truly is often stressful to respond to "what's greater effective powerful" questions, yet for this reason VB 2010 positioned across is obviously greater effective powerful. The VB 2010 language can do each and each little difficulty VB6 can and lots greater effective, and the type thoughts are a innovations superior in 2010. the main substantial distinction is that VB6 is now old college. The VB6 progression thoughts can now no longer be provided, and in case you do have a reproduction it truly is now no longer supported via potential of Microsoft. Microsoft additionally does no longer help working the type gadget on a sixty 4-bit OS. VB6 apps will run on all contemporary Microsoft OSs, yet there's no assure that this would proceed in destiny adjustments.
em2
2009-01-29 16:55:58 UTC
Create two global variables like this



Private seconds As Integer

Const START_TIME As Date = "00:03:00"



in command_button_to_start_timer()

seconds = 0



in timer()

seconds = seconds + 1



Label1.Caption = Right(Format(DateAdd("s", seconds * -1, START_TIME), "hh:mm:ss"), 5)



If Label1.Caption = "00:00" Then Timer1.Enabled = False


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...