I'm trying to make a program that plays different music in the background every hour. It plays the right music, but it's not changing. Can anyone help?
Public Class Form1 Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load Dim MyTime As Date Dim MyDate As Date 'Dim year As Date MyTime = Microsoft.VisualBasic.DateAndTime.TimeOfDay MyDate = Microsoft.VisualBasic.DateAndTime.Today 'year = Microsoft.VisualBasic.DateAndTime.Year TextBox1.Text = "False" If MyTime > "12:00:00 AM" And MyTime < "1:00:00 AM" Then If TextBox1.Text = "True" Then Else My.Computer.Audio.Stop() My.Computer.Audio.Play(My.Resources.midnight1, AudioPlayMode.BackgroundLoop) End If ElseIf MyTime > "1:00:00 AM" And MyTime < "2:00:00 AM" Then If TextBox1.Text = "True" Then Else My.Computer.Audio.Stop() My.Computer.Audio.Play(My.Resources._038___1_AM__Normal_, AudioPlayMode.BackgroundLoop) End If ElseIf MyTime > "2:00:00 AM" And MyTime < "3:00:00 AM" Then If TextBox1.Text = "True" Then Else My.Computer.Audio.Stop() My.Computer.Audio.Play(My.Resources._039___2_AM__Normal_, AudioPlayMode.BackgroundLoop) End If ElseIf MyTime > "3:00:00 AM" And MyTime < "4:00:00 AM" Then If TextBox1.Text = "True" Then Else My.Computer.Audio.Stop() My.Computer.Audio.Play(My.Resources._040___3_AM__Normal_, AudioPlayMode.BackgroundLoop) End If ElseIf MyTime > "4:00:00 AM" And MyTime < "5:00:00 AM" Then If TextBox1.Text = "True" Then Else My.Computer.Audio.Stop() My.Computer.Audio.Play(My.Resources._041___4_AM__Normal_, AudioPlayMode.BackgroundLoop) End If ElseIf MyTime > "5:00:00 AM" And MyTime < "6:00:00 AM" Then If TextBox1.Text = "True" Then Else My.Computer.Audio.Stop() My.Computer.Audio.Play(My.Resources._042___5_AM__Normal_, AudioPlayMode.BackgroundLoop) End If ElseIf MyTime > "6:00:00 AM" And MyTime < "7:00:00 AM" Then If TextBox1.Text = "True" Then Else My.Computer.Audio.Stop() My.Computer.Audio.Play(My.Resources._043___6_AM__Normal_, AudioPlayMode.BackgroundLoop) End If ElseIf MyTime > "7:00:00 AM" And MyTime < "8:00:00 AM" Then If TextBox1.Text = "True" Then Else My.Computer.Audio.Stop() My.Computer.Audio.Play(My.Resources._044___7_AM__Normal_, AudioPlayMode.BackgroundLoop) End If ElseIf MyTime > "8:00:00 AM" And MyTime < "9:00:00 AM" Then If TextBox1.Text = "True" Then Else My.Computer.Audio.Stop() My.Computer.Audio.Play(My.Resources._045___8_AM__Normal_, AudioPlayMode.BackgroundLoop) End If ElseIf MyTime > "9:00:00 AM" And MyTime < "10:00:00 AM" Then If TextBox1.Text = "True" Then Else My.Computer.Audio.Stop() My.Computer.Audio.Play(My.Resources._046___9_AM__Normal_, AudioPlayMode.BackgroundLoop) End If ElseIf MyTime > "10:00:00 AM" And MyTime < "11:00:00 AM" Then If TextBox1.Text = "True" Then Else My.Computer.Audio.Stop() My.Computer.Audio.Play(My.Resources._047___10_AM__Normal_, AudioPlayMode.BackgroundLoop) End If ElseIf MyTime > "11:00:00 AM" And MyTime < "12:00:00 PM" Then If TextBox1.Text = "True" Then Else My.Computer.Audio.Stop() My.Computer.Audio.Play(My.Resources._048___11_AM__Normal_, AudioPlayMode.BackgroundLoop) End If ElseIf MyTime > "12:00:00 PM" And MyTime < "1:00:00 PM" Then If TextBox1.Text = "True" Then Else My.Computer.Audio.Stop() My.Computer.Audio.Play(My.Resources._049___Noon__Normal_, AudioPlayMode.BackgroundLoop) End If ElseIf MyTime > "1:00:00 PM" And MyTime < "2:00:00 PM" Then If TextBox1.Text = "True" Then Else My.Computer.Audio.Stop() My.Computer.Audio.Play(My.Resources._050___1_PM__Normal_, AudioPlayMode.BackgroundLoop) End If ElseIf MyTime > "2:00:00 PM" And MyTime < "3:00:00 PM" Then If TextBox1.Text = "True" Then Else My.Computer.Audio.Stop() My.Computer.Audio.Play(My.Resources._051___2_PM__Normal_, AudioPlayMode.BackgroundLoop) End If ElseIf MyTime > "3:00:00 PM" And MyTime < "4:00:00 PM" Then If TextBox1.Text = "True" Then Else My.Computer.Audio.Stop() My.Computer.Audio.Play(My.Resources._052___3_PM__Normal_, AudioPlayMode.BackgroundLoop) End If ElseIf MyTime > "4:00:00 PM" And MyTime < "5:00:00 PM" Then If TextBox1.Text = "True" Then Else My.Computer.Audio.Stop() My.Computer.Audio.Play(My.Resources._053___4_PM__Normal_, AudioPlayMode.BackgroundLoop) End If ElseIf MyTime > "5:00:00 PM" And MyTime < "6:00:00 PM" Then If TextBox1.Text = "True" Then Else My.Computer.Audio.Stop() My.Computer.Audio.Play(My.Resources._054___5_PM__Normal_, AudioPlayMode.BackgroundLoop) End If ElseIf MyTime > "6:00:00 PM" And MyTime < "7:00:00 PM" Then If TextBox1.Text = "True" Then Else My.Computer.Audio.Stop() My.Computer.Audio.Play(My.Resources._055___6_PM__Normal_, AudioPlayMode.BackgroundLoop) End If ElseIf MyTime > "7:00:00 PM" And MyTime < "8:00:00 PM" Then If TextBox1.Text = "True" Then Else My.Computer.Audio.Stop() My.Computer.Audio.Play(My.Resources._056___7_PM__Normal_, AudioPlayMode.BackgroundLoop) End If ElseIf MyTime > "8:00:00 PM" And MyTime < "9:00:00 PM" Then If TextBox1.Text = "True" Then Else My.Computer.Audio.Stop() My.Computer.Audio.Play(My.Resources._057___8_PM__Normal_, AudioPlayMode.BackgroundLoop) End If ElseIf MyTime > "9:00:00 PM" And MyTime < "10:00:00 PM" Then If TextBox1.Text = "True" Then Else My.Computer.Audio.Stop() My.Computer.Audio.Play(My.Resources._058___9_PM__Normal_, AudioPlayMode.BackgroundLoop) End If ElseIf MyTime > "10:00:00 PM" And MyTime < "11:00:00 PM" Then If TextBox1.Text = "True" Then Else My.Computer.Audio.Stop() My.Computer.Audio.Play(My.Resources._059___10_PM__Normal_, AudioPlayMode.BackgroundLoop) End If ElseIf MyTime > "11:00:00 PM" And MyTime < "12:00:00 AM" Then If TextBox1.Text = "True" Then Else My.Computer.Audio.Stop() My.Computer.Audio.Play(My.Resources._060___11_PM__Normal_, AudioPlayMode.BackgroundLoop) End If End If End Sub End Class
Last edited by GameHutSoftware (2012-06-10 14:20:08)
Offline
Bumping
Up
My
Post
If
N00bs
Get
Undershirt
Pies
Last edited by GameHutSoftware (2012-06-10 01:16:39)
Offline
I can tell you that the problem is with comparing the date and time to a string. I would change all the if statement bits to something like this:
dim ts As Timespan ts = Date.Now.TimeOfDay If ts.Hours >= 7 And ts.Hours <= 8 Then 'play sound here End If
I havent tested this code but if the time is between 7am and 8am it will play the sound for that time. Hope this helps and post back if you need more help.
Offline
Daffy22 wrote:
I can tell you that the problem is with comparing the date and time to a string. I would change all the if statement bits to something like this:
Code:
dim ts As Timespan ts = Date.Now.TimeOfDay If ts.Hours >= 7 And ts.Hours <= 8 Then 'play sound here End IfI havent tested this code but if the time is between 7am and 8am it will play the sound for that time. Hope this helps and post back if you need more help.
Will that make it change on the hour? Mine plays the right music but it doesn't switch.
Offline
Okay, I've figured that it won't switch because I'm using the Form1_Load event. I s there an event for when the sound ends?
Offline
GameHutSoftware wrote:
Daffy22 wrote:
I can tell you that the problem is with comparing the date and time to a string. I would change all the if statement bits to something like this:
Code:
dim ts As Timespan ts = Date.Now.TimeOfDay If ts.Hours >= 7 And ts.Hours <= 8 Then 'play sound here End IfI havent tested this code but if the time is between 7am and 8am it will play the sound for that time. Hope this helps and post back if you need more help.
Will that make it change on the hour? Mine plays the right music but it doesn't switch.
Yeah if you replace all your if statements with this (and change the numbers) it will player dfferent sounds at different times
Offline
Daffy22 wrote:
GameHutSoftware wrote:
Daffy22 wrote:
I can tell you that the problem is with comparing the date and time to a string. I would change all the if statement bits to something like this:
Code:
dim ts As Timespan ts = Date.Now.TimeOfDay If ts.Hours >= 7 And ts.Hours <= 8 Then 'play sound here End IfI havent tested this code but if the time is between 7am and 8am it will play the sound for that time. Hope this helps and post back if you need more help.
Will that make it change on the hour? Mine plays the right music but it doesn't switch.
Yeah if you replace all your if statements with this (and change the numbers) it will player dfferent sounds at different times
Awesome. Does it use the 24 hour clock? (like, midnight would be 0?)
Offline
GameHutSoftware wrote:
Daffy22 wrote:
GameHutSoftware wrote:
Will that make it change on the hour? Mine plays the right music but it doesn't switch.Yeah if you replace all your if statements with this (and change the numbers) it will player dfferent sounds at different times
Awesome. Does it use the 24 hour clock? (like, midnight would be 0?)
Yes it does. So 8 pm would be 20
Offline
I meant by "changing on the hour" is that it actually changed during the runtime. Is there an event for when the sound ends?
Offline
It works!
Offline