Click here to Skip to main content
15,885,953 members
Articles / Desktop Programming / Windows Forms
Article

Multiplication Table Practice Tool

Rate me:
Please Sign up or sign in to vote.
4.33/5 (6 votes)
25 Dec 2008BSD3 min read 63.5K   3.4K   42   11
A kid friendly program for practicing multiplication tables; a good example for embedding the Windows Media Player control in an application.

Image 1

Introduction

I have two school age children, both learning and/or practicing their multiplication tables. I wrote this program to help them practice their multiplication tables in a fun way and focus on specific tables as needed. To help it be more fun, I wanted it to play music in the background and provide good A/V feedback based on correct or incorrect responses. I found lots of applications out there that does this sort of thing, but usually, they were something to buy or web based applications. I wanted something that was customizable, and could run locally without worrying with a browser or an Internet connection. I also wanted an application that could run easily from the numeric keypad while practicing – these were especially important since the target audience was younger children.

Background

I had never attempted to put background music in an application, so I tinkered with several options. In the end, I went with embedding a Windows Media Player control into the application (see Embedding Windows Media Player below to see how). It was flexible, and natively supported a large variety of musical formats.

Using the Windows Media Player Control

The actual documentation of the Windows Media Player Control can be found on MSDN. I’ll focus on the properties I needed in this simple application.

The media player control has a settings property that allows access to several playing attributes (e.g., auto-start, play count, and volume). The following code shows how these were applied:

VB
' We just use Windows Media Player to play background music
With MediaPlayer
    With .settings
        .autoStart = False
        .playCount = Integer.MaxValue
        .volume = 10
    End With

    .URL = Application.StartupPath & "\Audio\BackgroundJam.wma"
End With

Note that I simply set the play count to the maximum integer value to, in effect, create an endless playing loop for the music. Volume was set to 10, nice and low for background music - but not too distracting.

To play and pause the music, you access the Ctlcontrols property as follows:

VB
Private Sub StartBackgroundMusic()

    If m_backgroundMusicEnabled Then
        With MediaPlayer.Ctlcontrols
            .currentPosition = 0
            .play()
        End With
    End If

End Sub

Private Sub StopBackgroundMusic()

    MediaPlayer.Ctlcontrols.stop()

End Sub

Embedding the Windows Media Player

To embed the Windows Media Player control into your own application, you must click “Choose Items” from the Visual Studio toolbox (visible when a form is in design mode), then select the “COM Components” tab – be patient, this may take a while to load. If you have Windows Media Player installed on your system, there should be a COM component labeled “Windows Media Player” with a path such as C:\Windows\system32\wmp.dll; check this item, and click OK. If all you want is music in your application (i.e., not video), make sure and set the Visible property of the control to False.

Points of Interest

There is a class provided (ConfigurationSettings.vb) in the source code that simplifies the usage of saving and retrieving settings from a local configuration file. It automatically casts settings to and from Boolean and Integer values; here is an example of its usage:

VB
Private Sub PracticeTool_FormClosing(ByVal sender As Object, ByVal e As _
        System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing

    m_countDownTimer.Enabled = False
    BooleanSetting("RandomTestOrder") = m_randomTestOrder
    BooleanSetting("IncludeZeroInRange") = m_includeZeroInRange
    BooleanSetting("AudioFeedbackEnabled") = m_audioFeedbackEnabled
    BooleanSetting("BackgroundMusicEnabled") = m_backgroundMusicEnabled
    BooleanSetting("BackgroundMusicAlwaysOn") = m_backgroundMusicAlwaysOn
    IntegerSetting("CorrectAnswerDelay") = m_correctAnswerDelay
    IntegerSetting("IncorrectAnswerDelay") = m_incorrectAnswerDelay
    IntegerSetting("CountDownTime") = m_countDownTime
    BooleanSetting("WrongAnswerOnTimeout") = m_wrongAnswerOnTimeout
    Setting("PracticeNumbers") = Numbers.Text
    Setting("PracticeRange") = Range.Text
    Setting("ChildsName") = m_childsName
    SaveSettings()

End Sub

Generally, this application should be a good example for anyone getting started with VB.NET.

Using the Application

Assuming you actually got to this page to simply use this program for your own child, no worries – usage should be simple enough. All you need to do is just deploy the binaries into their own folder and run the executable. Watch for tool-tips for help, and adjust the options as needed. Again, the application uses the Windows Media Player control internally, so having Windows Media Player installed is a prerequisite. There are several options to tailor the usage to an individual child’s needs:

Multiplication_Table_Practice_Tool_Options.JPG

Additionally, the audio used by the program can be easily changed in the "Audio" folder to fit your child's interests a little better - this includes a "background jam" to keep things interesting. Simply override the existing files with the sound files of your preference, just make sure and use the same file names.

License

This article, along with any associated source code and files, is licensed under The BSD License


Written By
Architect
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
SuggestionWhy use an embedded Windows Media system? Pin
Member 101318193-Jul-13 3:44
Member 101318193-Jul-13 3:44 
GeneralRe: Why use an embedded Windows Media system? Pin
James Ritchie Carroll16-Jul-19 10:23
James Ritchie Carroll16-Jul-19 10:23 
QuestionImprovements ? Pin
scalpa9825-Nov-10 8:20
scalpa9825-Nov-10 8:20 
Questionm_practiceSetIndex = -1 Pin
scalpa9820-Nov-10 8:31
scalpa9820-Nov-10 8:31 
AnswerRe: m_practiceSetIndex = -1 Pin
James Ritchie Carroll22-Nov-10 2:54
James Ritchie Carroll22-Nov-10 2:54 
GeneralRe: m_practiceSetIndex = -1 Pin
scalpa9823-Nov-10 8:46
scalpa9823-Nov-10 8:46 
GeneralRe: m_practiceSetIndex = -1 Pin
James Ritchie Carroll23-Nov-10 8:56
James Ritchie Carroll23-Nov-10 8:56 
GeneralMy students absolutely love the interface. I work with many older student who do not know the multiplication tables. Pin
bobrindner3-Dec-09 18:54
bobrindner3-Dec-09 18:54 
GeneralRe: My students absolutely love the interface. I work with many older student who do not know the multiplication tables. Pin
James Ritchie Carroll14-Jul-10 8:56
James Ritchie Carroll14-Jul-10 8:56 
GeneralFantastic Pin
infinitebuzz29-Dec-08 16:30
infinitebuzz29-Dec-08 16:30 
GeneralGreat! Pin
King_kLAx26-Dec-08 0:56
King_kLAx26-Dec-08 0:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.