This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-06-08 13:19:17

GameHutSoftware
Scratcher
Registered: 2010-04-24
Posts: 1000+

A little more VB.NET help?

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?

Code:

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)


Lurking more than posting, but still here.

Offline

 

#2 2012-06-10 01:16:18

GameHutSoftware
Scratcher
Registered: 2010-04-24
Posts: 1000+

Re: A little more VB.NET help?

Bumping
Up
My
Post
If
N00bs
Get

Undershirt
Pies

Last edited by GameHutSoftware (2012-06-10 01:16:39)


Lurking more than posting, but still here.

Offline

 

#3 2012-06-10 03:24:09

Daffy22
Scratcher
Registered: 2008-12-15
Posts: 500+

Re: A little more VB.NET help?

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 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.  smile


http://img201.imageshack.us/img201/1784/logosmalle.png
"Spectacular - 5 Star" -  CNET.com Editor.

Offline

 

#4 2012-06-10 13:58:41

GameHutSoftware
Scratcher
Registered: 2010-04-24
Posts: 1000+

Re: A little more VB.NET help?

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 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.  smile

Will that make it change on the hour? Mine plays the right music but it doesn't switch.


Lurking more than posting, but still here.

Offline

 

#5 2012-06-10 17:16:27

GameHutSoftware
Scratcher
Registered: 2010-04-24
Posts: 1000+

Re: A little more VB.NET help?

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?


Lurking more than posting, but still here.

Offline

 

#6 2012-06-10 17:17:35

Daffy22
Scratcher
Registered: 2008-12-15
Posts: 500+

Re: A little more VB.NET help?

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 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.  smile

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


http://img201.imageshack.us/img201/1784/logosmalle.png
"Spectacular - 5 Star" -  CNET.com Editor.

Offline

 

#7 2012-06-10 17:22:29

GameHutSoftware
Scratcher
Registered: 2010-04-24
Posts: 1000+

Re: A little more VB.NET help?

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 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.  smile

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?)


Lurking more than posting, but still here.

Offline

 

#8 2012-06-10 17:27:40

Daffy22
Scratcher
Registered: 2008-12-15
Posts: 500+

Re: A little more VB.NET help?

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


http://img201.imageshack.us/img201/1784/logosmalle.png
"Spectacular - 5 Star" -  CNET.com Editor.

Offline

 

#9 2012-06-10 18:01:28

GameHutSoftware
Scratcher
Registered: 2010-04-24
Posts: 1000+

Re: A little more VB.NET help?

I meant by "changing on the hour" is that it actually changed during the runtime.  Is there an event for when the sound ends?


Lurking more than posting, but still here.

Offline

 

#10 2012-06-12 20:39:50

GameHutSoftware
Scratcher
Registered: 2010-04-24
Posts: 1000+

Re: A little more VB.NET help?

It works!


Lurking more than posting, but still here.

Offline

 

Board footer