Solved

Sub Menu selection stored in a variable

Posted on 2012-03-29
6
313 Views
Last Modified: 2012-04-04
Alarm Clock App Description:
I’ve developed a simple alarm clock in visual studio 2010. So far, I have a form  with a menu that allows the user to set an alarm and  turn it on and off.  When the user selects set from the menu, it shows another dialog form (getTime.vb) with a masked Textbox (mskTime) Mask=time(US) and two radio buttons to set either AM or PM (radAM, radPM). When the user enters a time in the textbox and selects the radio button (AM or PM) the value is stored in a label on Form1(lblAlarmTime). Also on form1 is two timers to capture the current time and to advance the time every second and the value is stored in another label (lblTimeOfDay). If lblAlarmTime = lblTimeOfDay, it plays an audio sound (My.Computer.Audio.Play(My.Resources.beep_20.Background).

Here’s what I need help with:
I want to add a menu item so the user can select an alarm sound instead of it already being hard coded in my if statement.  I would like there to be 3 sub menus under the “Change” menu item for 3 different options(“Beeping”,”Music”,”Speech”). The “Speech” selection is to be SAPI.  I’m new to this and I’m not sure how to go about detecting which sub menu item the user selects and store it in a variable to be used in the Audio.Play of my "if statement".
0
Comment
Question by:ktjamms2
  • 5
6 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 37782992
You can define an enum

Public Enum SoundMode
Beeping
Music
Speech
End Enum

then declare a form level variable of this enum. In your menu handlers, you can change it
for example
CurrentSoundMode = SoundMode.Music
0
 

Author Comment

by:ktjamms2
ID: 37783111
Where should the enum be defined?
0
 

Author Comment

by:ktjamms2
ID: 37787079
I had in mind creating a sub something like this example below, but it doesn't work yet.
Then use my if statement to call the sub.

Private Sub SoundAlarm()
        Dim SAPI
        SAPI = CreateObject("sapi.spvoice")

        If BeepingToolStripMenuItem1.PerformClick Then
            My.Computer.Audio.Play(My.Resources.beep_20, AudioPlayMode.Background)
        End If

        If MusicToolStripMenuItem1.PerformClick Then
            My.Computer.Audio.Play(My.Resources.beep_20, AudioPlayMode.Background)
        End If

        If SpeechToolStripMenuItem.PerformClick Then
            SAPI.Speak(txtEnterWords.Text)
        End If
    End Sub

Then in my if statement:
If lblAlarmTime.Text = lblTimeOfDay.Text Then
            SoundAlarm()
            MsgBox("wake up!")
        End If

 If MusicToolStripMenuItem1.PerformClick  ----error "expression does not produce a value"

I don't know how to detect when the submenue is clicked. I would like to figure this out and figure out how to put a check mark next to the sub menu item that is selected. Any help would be greatly appreciated!
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:ktjamms2
ID: 37787706
This is what I have so far with no errors, but it is not playing the sound and it won't uncheck the submenu item when another one is checked so that only one selection is checked.

Private Sub SoundAlarm()
        Dim SAPI
        SAPI = CreateObject("sapi.spvoice")

        If BeepingToolStripMenuItem1.CheckState = True Then
            My.Computer.Audio.Play(My.Resources.beep_20, AudioPlayMode.Background)
            MusicToolStripMenuItem1.CheckState = False
            SpeechToolStripMenuItem.CheckState = False
        End If

        If MusicToolStripMenuItem1.CheckState = True Then
            My.Computer.Audio.Play(My.Resources.beep_20, AudioPlayMode.Background)
            BeepingToolStripMenuItem1.CheckState = False
            SpeechToolStripMenuItem.CheckState = False
        End If

        If SpeechToolStripMenuItem.CheckState = True Then
            SAPI.Speak(txtEnterWords.Text)
            MusicToolStripMenuItem1.CheckState = False
            BeepingToolStripMenuItem.CheckState = False
        End If
    End Sub

Then in my if statement is this:
If lblAlarmTime.Text = lblTimeOfDay.Text Then
            SoundAlarm()
            MsgBox("wake up!")
        End If
0
 

Accepted Solution

by:
ktjamms2 earned 0 total points
ID: 37789284
I got this to work except for the voice

Private Sub SoundAlarm()
        Dim SAPI
        SAPI = CreateObject("sapi.spvoice")

        If BeepingToolStripMenuItem1.Checked = True Then
            My.Computer.Audio.Play(My.Resources.beep_20, AudioPlayMode.Background)
            MusicToolStripMenuItem1.CheckState = False
            SpeechToolStripMenuItem.CheckState = False
        End If

        If MusicToolStripMenuItem1.Checked = True Then
            My.Computer.Audio.Play(My.Resources.beep_1, AudioPlayMode.Background)
            BeepingToolStripMenuItem1.CheckState = False
            SpeechToolStripMenuItem.CheckState = False
        End If

        If SpeechToolStripMenuItem.Checked = True Then
            SAPI.Speak(txtEnterWords.Text)
            SAPI.rate = 100
            SAPI.volume = 200
            MusicToolStripMenuItem1.CheckState = False
            BeepingToolStripMenuItem.CheckState = False
        End If
    End Sub
0
 

Author Closing Comment

by:ktjamms2
ID: 37805206
no other understandable solutions were offered
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now