yes hi
i know there are tons of threads on alarm clocks
please help on this one
i have a label control that i want the time to show in
i just want to display the 24hr version of the time in the label THAT'S it
:( :(
Printable View
yes hi
i know there are tons of threads on alarm clocks
please help on this one
i have a label control that i want the time to show in
i just want to display the 24hr version of the time in the label THAT'S it
:( :(
Put a Timer on your form and set Enabled to True and Interval to 1000, then double click it to create a Tick event handler:As for the sound file, you should look into the PlaySound API function. It has been mentioned plenty of times on this forum so a search will turn up multiple matches. You could also search for it on MSDN where ther are several examples of how to use it. You would simply check whether the current time is greater than your alarm time and the difference is less than 1 second. Those conditions would indicate that this is the first Tick event after the alarm time and it's time to play the file.VB Code:
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick Me.Label1.Text = Date.Now.ToString("H:mm:ss") End Sub
the cpu light keeps active
how do i keep my clock program from using the proessor all the time
also how do i make the time move around the form like a screensaver
i have to go to work at 8am
instead of buying a clock im cheap and wanna build one
i want the program to run all the time but i don't want a burn in image on my LCD
first add a timer control it is found in toolbox in a design mode of your form
then do thisVB Code:
Dim starttime As DateTime Dim span, prevspan As TimeSpan Dim totalspan As New TimeSpan(0, 0, 0, 0, 0) 'in your form load Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Timer1.Start() End Sub 'timer tick event of your timer Private Sub timertick_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick span = Date.Now.Subtract(starttime) totalspan = prevspan totalspan = totalspan.Add(span) Label1.Text = totalspan.Hours.ToString & " : " & totalspan.Minutes.ToString & ":" & totalspan.Seconds.ToString End Sub
nah jchlimmey got it.
A Timer with a 1 second Interval will use very few resources and will not affect your system noticeably. The light on your computer generally indicates hard disk activity rather than processor activity. If your HDD is churning it is not because of the code I provided.Quote:
Originally Posted by student_devry01
Burn in on modern monitors is virtually impossible. Screensavers only exist these days because people think they're pretty, not because we need them. If you want to make your Label move around your Form or your Form move around the screen, you should use a second Timer and when it ticks choose some position at random and position your control there:You would set the Timer's Interval to some suitable value like 30000 (30 seconds).VB Code:
Private m_RandNum As New Random(CInt(Date.Now.TimeOfDay.TotalSeconds)) Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick Const minX As Integer = 0 Const minY As Integer = 0 Dim maxX As Integer = Screen.PrimaryScreen.WorkingArea.Width - Me.Width Dim maxY As Integer = Screen.PrimaryScreen.WorkingArea.Height - Me.Height Me.Location = New Point(Me.m_RandNum.Next(minX, maxX), Me.m_RandNum.Next(minY, maxY)) End Sub
how do i link the code together
the label is call txt_time
You don't unless you want the form to move every second, which could get quite annoying. You put two different Timers on your form. One has an Interval of 1000 and is used to set the Label's Text every second. The second has an Interval of something like 30000 and is used to move the form every 30 seconds. They have completely seperate Tick event handlers. I've changed the name's of the variables to your convention. Just a note though, the "txt" prefix is usually used for a TextBox and "lbl" is used for a Label:VB Code:
Private m_RandNum As New Random(CInt(Date.Now.TimeOfDay.TotalSeconds)) Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.txt_time.Text = Date.Now.ToString("H:mm:ss") End Sub Private Sub tmr_time_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmr_time.Tick Me.txt_time.Text = Date.Now.ToString("H:mm:ss") End Sub Private Sub tmr_location_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmr_location.Tick Const minX As Integer = 0 Const minY As Integer = 0 Dim maxX As Integer = Screen.PrimaryScreen.WorkingArea.Width - Me.Width Dim maxY As Integer = Screen.PrimaryScreen.WorkingArea.Height - Me.Height Me.Location = New Point(Me.m_RandNum.Next(minX, maxX), Me.m_RandNum.Next(minY, maxY)) End Sub
also i want to remove the exit button when the clock hits midnight
i am going to setup a different timer for this
You don't need an extra Timer for that. Just test the time in the Tick event handler of the first Timer and if it has just passed midnight then do what you need to.
how??
i got the clock working
thanks JMC
i am trying to prevent someone from viewing my screen between the hours of 12am when i go to sleep and 8am when i wake up
so the exit button becomes disable at 12 and becomes enable at 8am
by itself
This code will allow you to perform an action on the first Tick event after midnight. You can do something similar to perform an action at any specified time. Don't place too much code in that Tick event handler, though, because it is being executed once every second. Lot's of code in that method will slow things down. The only way to know when you would notice a difference is to experiment. Also note that some of the variables would be better of being declared at the class level, but I'll leave thos details up to you.VB Code:
Private m_LastTick As Date = Date.Now Private Sub txt_time_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmr_time.Tick Dim currentTime As Date = Date.Now 'The current time. Dim alarmTime As TimeSpan = TimeSpan.FromHours(0) 'The time each day the alarm will go off. Set as required. Dim todaysAlarmTime As Date = Date.Today.Add(alarmTime) 'The time today the alarm should go off. If Me.m_LastTick < todaysAlarmTime AndAlso currentTime >= todaysAlarmTime Then 'The alarm time occurred within the time interval since the last tick so initiate the alarm event. End If Me.txt_time.Text = Date.Now.ToString("H:mm:ss") Me.m_LastTick = currentTime End Sub