Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> [vb.net 2k5] Countdown (help), countdown visual basic 2005 2k5
de4thpr00f
post Nov 21 2007, 02:15 PM
Post #1


Member [Level 2]
*****

Group: Members
Posts: 76
Joined: 21-November 07
Member No.: 53,412



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 seconds
the 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:
CODE
Imports System.Threading.Thread

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 start
stops:
MsgBox("countdown off")
End Sub
End 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)
CODE
Imports System.Threading.Thread

Public 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 Sub
End Class


This post has been edited by de4thpr00f: Nov 22 2007, 12:09 AM
Attached File(s)
Attached File  countdown.zip ( 54.66k ) Number of downloads: 0
Attached File  countdown_new_.zip ( 86.9k ) Number of downloads: 1
 
Go to the top of the page
 
+Quote Post
paulbacca
post Jan 7 2008, 08:46 AM
Post #2


Newbie
*

Group: Members
Posts: 2
Joined: 4-January 08
Member No.: 55,704



Hi de4thpr00f,
would you know how to add hours to your code below. I would appreciate any help you can give.
Thanks
Paul


[quote name='de4thpr00f' date='Nov 21 2007, 02:15 PM' post='358108']

CODE
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 start
stops:
MsgBox("countdown off")
End Sub
End Class
Go to the top of the page
 
+Quote Post
imbibe
post Jan 10 2008, 07:16 AM
Post #3


Member [Level 1]
****

Group: Members
Posts: 67
Joined: 25-June 06
From: Den
Member No.: 25,638



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.
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. [vb.net 2k5] Morsecode(0)
  2. [vb.net 2k5] Color Fading Textboxes(0)
  3. Countdown Timer(0)


 



- Lo-Fi Version Time is now: 30th August 2008 - 06:43 AM