Jump to content
xisto Community
Sign in to follow this  
de4thpr00f

[vb.net 2k5] Countdown (help) countdown visual basic 2005 2k5

Recommended Posts

Hello, i'm having some troubles creating a countdown, i'm willing for some help.First of all, the form has a textbox where the user has to input the time to countdown like this: 1:10 < this means 1 minute and 10 secondsthe form has also 3 labels, 1 named countminutes, other countseconds and another label1 with the text ":"here's the code, the problem is that it counts the time, but blocks the app till it ends, wich result on not showing the counttime like it should:

Imports System.Threading.ThreadPublic Class Form1    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click        Dim time() As String        time = Split(timetowait.Text, ":", , CompareMethod.Text)        countminutes.Text = time(0)        countseconds.Text = time(1)        Dim minutes As Integer = time(0)        Dim seconds As Integer = time(1)start:        If seconds = 0 And minutes = 0 Then            GoTo stops        End If        If seconds = 0 Then            minutes -= 1            seconds = 60        End If        seconds -= 1        countminutes.Text = minutes        countseconds.Text = seconds        Sleep(1000)        GoTo startstops:        MsgBox("countdown off")    End SubEnd Class

If someone could help me would be cool.If i pull this out before someone helps me i'll post the new code in here.Thanks in advance.~Jo?o Lopes*edit*Posted the attached file.*edit*Problem solved, i'll leave the 1st source there and attach another, the 1st source has nothing important, but uses the function sleep, and i don't know if it will not be needed around.and the code is this one (note, now a timer is needed, named timer1)

Imports System.Threading.ThreadPublic Class Form1    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click        If InStr(timetowait.Text, ":") Then            Dim time() As String            time = Split(timetowait.Text, ":", , CompareMethod.Text)            countminutes.Text = time(0)            countseconds.Text = time(1)            Timer1.Interval = 1000            Timer1.Start()        Else            MsgBox("You have to insert like this 1:10")        End If    End Sub    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick        Dim minutes As Integer = countminutes.Text        Dim seconds As Integer = countseconds.Text        If minutes = 0 And seconds = 0 Then            MsgBox("Time Ended")            Timer1.Stop()        End If        If seconds = 0 Then            minutes -= 1            seconds += 60        End If        seconds -= 1        If minutes <> -1 Then            countminutes.Text = minutes            countseconds.Text = seconds        End If    End SubEnd Class

countdown.zip

countdown_new_.zip

Edited by de4thpr00f (see edit history)

Share this post


Link to post
Share on other sites

Hi de4thpr00f,

would you know how to add hours to your code below. I would appreciate any help you can give.

Thanks

Paul

 

 

 

Public Class Form1    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click        Dim time() As String        time = Split(timetowait.Text, ":", , CompareMethod.Text)        countminutes.Text = time(0)        countseconds.Text = time(1)        Dim minutes As Integer = time(0)        Dim seconds As Integer = time(1)start:        If seconds = 0 And minutes = 0 Then            GoTo stops        End If        If seconds = 0 Then            minutes -= 1            seconds = 60        End If        seconds -= 1        countminutes.Text = minutes        countseconds.Text = seconds        Sleep(1000)        GoTo startstops:        MsgBox("countdown off")    End SubEnd Class

Share this post


Link to post
Share on other sites

You can convert hours to seconds and add them to the code.BTW for timer there's inbuilt control for Desktop & Web (using ASP.NET AJAX 1.0) Applications.Set the Interval property to seconds, minutes, even hours, days. Then handle the Tick Event.

Share this post


Link to post
Share on other sites
count down[vb.net 2k5] Countdown (help)

I am Cyrill of Philippines.. A student

I have a assignment we are making a score board about a basket ball game using visual basic

I can not make a timer for a basket ball game, I really do not know how to make a countdown for basket game.. Can you help pls... I really need it tomorrow thank you  and God BLESS

Share this post


Link to post
Share on other sites

i've just tried that code instead of having a button to start it i'm doing it in the form load. my time to count down is 5 minutes but when it starts it just goes down to 4:59 and does nothing. i waited the 5 minutes to see if it was the label and it wasn't what do you think is wrong?just to add im doing it so the time starts when the program does im not doing it so the user enters the time.this is my code

Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load?If InStr(Label3.Text, ":") Then?           Dim time() As String?           time = Split(Label3.Text, ":", , CompareMethod.Text)?           lblTimeMinutes.Text = time(0)?           lblTimeSeconds.Text = time(1)?           timer1.Interval = 1000?           timer1.Start()?          ??       End If?End Sub?Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles timer1.Tick?       Dim Minutes As Integer?       Dim Seconds As Integer?       Minutes = 5?       Seconds = 0?       If Minutes = 0 And Seconds = 0 Then?           MsgBox("Game Over")?           timer1.Stop()?           End?       End If?       If Seconds = 0 Then?           Minutes -= 1?           Seconds += 60?       End If?       Seconds -= 1?       If Minutes <> -1 Then?           lblTimeMinutes.Text = Minutes?           lblTimeSeconds.Text = Seconds?       End If?End Sub

Edited by defterniko (see edit history)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.