neodammer Posted August 10, 2005 Posted August 10, 2005 My alarm clock works during the morning hours pre-noon but after noon it fails to initalize. I am thinking it has something to do with 24 hour system vs. the am/pm. Here is my code Public curtime As Date Public hours As Int16 Public minutes As Int16 Public ampm As Boolean Public xampm As String Public timonoff As Boolean Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" _ (ByVal lpszName As String, ByVal dwFlags As Long) As Long Const SND_ASYNC = &H1 Public waveFileLoaded As Boolean = False Public Function App_Path() As String Return System.AppDomain.CurrentDomain.BaseDirectory() End Function Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If timonoff = True Then MsgBox("TIMER ALREADY STARTED! CANNOT STOP!! WAKE UP !!", , "I DONT THINK SO!") Exit Sub End If If ampm = True Then xampm = "AM" ElseIf ampm = False Then xampm = "PM" End If If ComboBox1.Text = "minutes" Then MsgBox("PLEASE SELECT HOUR and or MINUTES FOR ALARM!", , "ERROR") Exit Sub ElseIf ComboBox2.Text = "hour" Then MsgBox("PLEASE SELECT HOUR and or MINUTES FOR ALARM!", , "ERROR") Exit Sub End If timonoff = True If ComboBox1.Text = "1" Or ComboBox1.Text = "2" Or ComboBox1.Text = "3" Or ComboBox1.Text = "4" Or ComboBox1.Text = "5" Or ComboBox1.Text = "6" Or ComboBox1.Text = "7" Or ComboBox1.Text = "8" Or ComboBox1.Text = "9" Then TextBox1.Text = "ALARM SET FOR: " & ComboBox2.Text & ":" & "0" & ComboBox1.Text & " " & xampm Else TextBox1.Text = "ALARM SET FOR: " & ComboBox2.Text & ":" & ComboBox1.Text & " " & xampm End If End Sub Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick curtime = Microsoft.VisualBasic.DateAndTime.TimeOfDay timedisplaybox.Text = curtime.ToString("T") 'this next step is supposed to take the user input for the alarm time off combobox2 and combobox1 and then compare it to the current time in hours/seconds and then if it equils to be the same the message box comes up ' If CStr(hours) = CStr(curtime.Hour) AndAlso ampm = True AndAlso CStr(minutes) = CStr(curtime.Minute) AndAlso timonoff = True Then timonoff = False Dim playme As String MsgBox("MWUAHAHHAHA IT WORKS!", , "WORKS") playme = "C:" sndPlaySound(playme, SND_ASYNC) 'this is supposed to happen when the if statement is all true TextBox1.Text = "" 'clears the textbox where the alarm time was displayed timonoff = False 'this stops the alarm from auto-initalizing End End If If CStr(hours) = CStr(curtime.AddHours(12).Hour) AndAlso ampm = False AndAlso CStr(minutes) = CStr(curtime.Minute) AndAlso timonoff = True Then timonoff = False Dim playme As String MsgBox("Working!", , "WORKS") playme = "C:\music.wav" sndPlaySound(playme, SND_ASYNC) 'this is supposed to happen when the if statement is all true TextBox1.Text = "" 'clears the textbox where the alarm time was displayed 'this stops the alarm from auto-initalizing End If End Sub Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged CheckBox2.CheckState() = CheckState.Unchecked ampm = True End Sub Private Sub CheckBox2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox2.CheckedChanged CheckBox1.CheckState() = CheckState.Unchecked ampm = False End Sub Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged hours = ComboBox2.Text End Sub Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged minutes = ComboBox1.Text End Sub Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub Private Sub timedisplaybox_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles timedisplaybox.Click End Sub Quote Enzin Research and Development
Machaira Posted August 10, 2005 Posted August 10, 2005 Instead of comparing the individual components of the time, why not create a Time object from the components and compare it to curtime? Quote Here's what I'm up to.
Administrators PlausiblyDamp Posted August 10, 2005 Administrators Posted August 10, 2005 Firstly you have quite a lot of VB6 stuff in there - why not just use Date.Now to get the current time rather than going through the Microsoft.VisualBasic.DateAndTime object? Also instead of providing comboboxes to select the date why not just drop a DateTimePicker control on a form and set it's format property to time; that way you do not have to worry about validating the time or handling 12 / 24 hour formats yourself. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
neodammer Posted August 10, 2005 Author Posted August 10, 2005 (edited) I see I see thanks for the .net update :) This is an older project I threw together before studying all the updates in .net rofl as you can see of course. Question, when i set the datetimepicker to time I still get the calender when trying to set the date which of course i only want the clock not the days. Anyway to change this so i can change the time and not the dates? I could see how you could just compare the date and the time but that wouldnt work if your alarm was supposed to go off post midnight the next day unless you set an option to check if its tomorrow etc.. Edited August 10, 2005 by neodammer Quote Enzin Research and Development
Machaira Posted August 10, 2005 Posted August 10, 2005 Question' date=' when i set the datetimepicker to time I still get the calender when trying to set the date which of course i only want the clock not the days. Anyway to change this so i can change the time and not the dates?[/quote'] Set the ShowUpDown property to True. Quote Here's what I'm up to.
neodammer Posted August 10, 2005 Author Posted August 10, 2005 Awesome ^_^ thanks. is there a way to take away the seconds or leave it at 00 all the time? I mean if i just compare the date.now it will only say its equil when the seconds are equil which isnt a big deal i mean the alarm would go off within that minute but..exacts wont be possible that way. Thats why i need to do away with comparing the seconds. Quote Enzin Research and Development
Machaira Posted August 11, 2005 Posted August 11, 2005 Change the Format of the control to Custom and set the CustomFormat property to "hh:mm" Quote Here's what I'm up to.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.