This is just a fun simple program that I created during some free time at school. This is the first article I've posting, so please bear with me. :)
I've used an article written by Alastair Dallas: Tiny StopWatch Application.
I also used a little tutorial from: Using WMP.
Power Hour is a drinking game that many college students play. The idea is to take a shot of beer every minute for a whole hour. I've imported the Windows Media Player COM so that a song will change every minute.
Using the Code
The first code snippet is the button control click procedure.
Dim startTime As DateTime
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
If (Timer1.Enabled) Then
MessageBox.Show("You did not complete power hour", "Failed")
Label3.Text = String.Empty
Label4.Text = String.Empty
startTime = DateTime.Now()
Button1.Text = "Stop!"
The second code snippet is the timer control.
Private Sub Timer1_Tick(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Timer1.Tick
Dim span As TimeSpan = DateTime.Now.Subtract(startTime)
Label4.Text = span.Seconds.ToString
ProgressBar1.Value += 1
If ProgressBar1.Value = 60 Then
ProgressBar1.Value = 0
ProgressBar2.Value += 1
Dim span2 As TimeSpan = DateTime.Now.Subtract(startTime)
Label3.Text = span2.Minutes.ToString
If ProgressBar2.Value = 60 Then
MessageBox.Show("You've completed power hours", _
"Congratulations!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
ProgressBar2.Value = 0
The third code snippet is the menu item to import a playlist.
Private Sub AddMusicToolStripMenuItem_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles AddMusicToolStripMenuItem.Click
Dim dlg As New OpenFileDialog()
dlg.InitialDirectory = "C:\"
dlg.CheckFileExists = True
dlg.Title = "Import a Playlist from WMP"
dlg.Filter = "Windows Media Playlists|*.wpl"
dlg.Multiselect = False
wmp.URL = dlg.FileName
That's all the code there is for this little project. You need to add the Windows Media Player COM however. To do this, right click on the tool box, select Choose Items.... select COM Components and check Windows Media Player. Now you can add the control to your form.
Points of Interest
The neatest thing about this was the WMP COM. I made it so that people can import their WMP play lists in there and the timer switches the song every minute. This stops people from editing the whole song and cutting it off at a minute like I've seen people do.
If you have any questions, please e-mail me at email@example.com.
- 31st July, 2007: Initial post