hello friend s i am making the simple timer module which will display time in count down format
as if user wnters 1 hour 3 mins and 30 sec so it will count in revers i have almost half code done but afer trying the all tricks and logic i didnt got any thing the out put is not proper as which i want

the code is as follows

Public Class Form1
    Public hh As Integer
    Public mm As Integer
    Public ss As Integer
    Public totalsec As Integer
    Public timercount As Integer
    Public temp As Integer


    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
        hh = Val(TextBox1.Text)

    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged
        mm = Val(TextBox2.Text)

    End Sub

    Private Sub TextBox3_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox3.TextChanged
        ss=Val(TextBox3 .Text )

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        totalsec = (hh * 3600) + (mm * 60) + ss

        hh = totalsec / 3600
        totalsec = totalsec - (hh * 3600)
        mm = totalsec / 60
        totalsec = totalsec - (mm * 60)
        ss = totalsec

        Label1.Text = hh.ToString
        Label2.Text = mm.ToString
        Label3.Text = ss.ToString
        timercount = totalsec
    End Sub

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

        ' totalsec = totalsec - 1
        timercount = timercount - 1
        temp = timercount
        hh = temp / 3600
        Label1.Text = hh.ToString
        temp = temp - (hh * 3600)
        mm = temp / 60
        Label2.Text = mm.ToString
        temp = temp - (mm * 60)
        ss = temp
        Label3.Text = ss.ToString

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        Timer1.Enabled = True
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Timer1.Enabled = False
    End Sub
End Class

Recommended Answers

All 6 Replies

please help me out i am so firstrated please god help me?

dkalmase, there is another thread within daniweb that should help.
There is a timer function within VB, and it does what your looking for, and with a lot less code. here is the link for the thread.
http://www.daniweb.com/forums/thread14312.html

I am not sure if you were able to get anything accomplished from the posted link,
but I could not figure out what a Label.Caption is.:D

I hope this is a little more up to date.

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Button1.Text = "Start"
        Timer1.Interval = 1000 '// tick every second.
        '// textbox1 = Hours, textbox2 = Minutes, textbox3 = Seconds
        TextBox1.Text = "0" : TextBox2.Text = "0" : TextBox3.Text = "0"
     End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If Timer1.Enabled = False Then
            Timer1.Start()
            Button1.Text = "Stop"
        Else
            Timer1.Stop()
            Button1.Text = "Start"
        End If
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        If TextBox1.TextLength < 2 Then TextBox1.Text = "0" & TextBox1.Text '// format from "0" to "00"
        '// verify Hours.
        If TextBox1.Text > "00" And TextBox2.Text = "00" Then
            TextBox1.Text -= 1
            TextBox2.Text = "60"
        End If
       
        If TextBox2.TextLength < 2 Then TextBox2.Text = "0" & TextBox2.Text '// format from "0" to "00"
        '// verify Minutes.
        If TextBox2.Text > "00" And TextBox3.Text = "00" Then
            TextBox2.Text -= 1
            TextBox3.Text = "60"
        End If
       
        If TextBox3.TextLength < 2 Then TextBox3.Text = "0" & TextBox3.Text '// format from "0" to "00"
        '// verify Seconds.
        If TextBox3.Text > "00" Then TextBox3.Text -= 1
       
        '// disable Timer.
        If TextBox1.Text = "00" And TextBox2.Text = "00" AndAlso TextBox3.Text = "00" Then
            Timer1.Enabled = False
            MsgBox("Can I stop counting now?  :)", MsgBoxStyle.Information)
            Button1.Text = "Start"
        End If
    End Sub
End Class

thak you for ur help but my logic is also working as i new for this vb.net so i used the '/'sign for mod instead of '\' so it is not working

#include

just checking it works or not

hello friend s i am making the simple timer module which will display time in count down format
as if user wnters 1 hour 3 mins and 30 sec so it will count in revers i have almost half code done but afer trying the all tricks and logic i didnt got any thing the out put is not proper as which i want

the code is as follows

Public Class Form1
Public hh As Integer
Public mm As Integer
Public ss As Integer
Public totalsec As Integer
Public timercount As Integer
Public temp As Integer


Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
hh = Val(TextBox1.Text)

End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

End Sub

Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged
mm = Val(TextBox2.Text)

End Sub

Private Sub TextBox3_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox3.TextChanged
ss=Val(TextBox3 .Text )

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
totalsec = (hh * 3600) + (mm * 60) + ss

hh = totalsec / 3600
totalsec = totalsec - (hh * 3600)
mm = totalsec / 60
totalsec = totalsec - (mm * 60)
ss = totalsec

Label1.Text = hh.ToString
Label2.Text = mm.ToString
Label3.Text = ss.ToString
timercount = totalsec
End Sub

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

' totalsec = totalsec - 1
timercount = timercount - 1
temp = timercount
hh = temp \ 3600
Label1.Text = hh.ToString
temp = temp - (hh * 3600)
mm = temp \60
Label2.Text = mm.ToString
temp = temp - (mm * 60)
ss = temp
Label3.Text = ss.ToString

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

Timer1.Enabled = True
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Timer1.Enabled = False
End Sub
End Class
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.