ktjamms2
asked on
Sub Menu selection stored in a variable
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.B ackground) .
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".
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
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”,
ASKER
Where should the enum be defined?
ASKER
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. PerformCli ck Then
My.Computer.Audio.Play(My. Resources. beep_20, AudioPlayMode.Background)
End If
If MusicToolStripMenuItem1.Pe rformClick Then
My.Computer.Audio.Play(My. Resources. beep_20, AudioPlayMode.Background)
End If
If SpeechToolStripMenuItem.Pe rformClick Then
SAPI.Speak(txtEnterWords.T ext)
End If
End Sub
Then in my if statement:
If lblAlarmTime.Text = lblTimeOfDay.Text Then
SoundAlarm()
MsgBox("wake up!")
End If
If MusicToolStripMenuItem1.Pe rformClick ----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!
Then use my if statement to call the sub.
Private Sub SoundAlarm()
Dim SAPI
SAPI = CreateObject("sapi.spvoice
If BeepingToolStripMenuItem1.
My.Computer.Audio.Play(My.
End If
If MusicToolStripMenuItem1.Pe
My.Computer.Audio.Play(My.
End If
If SpeechToolStripMenuItem.Pe
SAPI.Speak(txtEnterWords.T
End If
End Sub
Then in my if statement:
If lblAlarmTime.Text = lblTimeOfDay.Text Then
SoundAlarm()
MsgBox("wake up!")
End If
If MusicToolStripMenuItem1.Pe
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!
ASKER
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.Ch eckState = False
SpeechToolStripMenuItem.Ch eckState = False
End If
If MusicToolStripMenuItem1.Ch eckState = True Then
My.Computer.Audio.Play(My. Resources. beep_20, AudioPlayMode.Background)
BeepingToolStripMenuItem1. CheckState = False
SpeechToolStripMenuItem.Ch eckState = False
End If
If SpeechToolStripMenuItem.Ch eckState = True Then
SAPI.Speak(txtEnterWords.T ext)
MusicToolStripMenuItem1.Ch eckState = False
BeepingToolStripMenuItem.C heckState = False
End If
End Sub
Then in my if statement is this:
If lblAlarmTime.Text = lblTimeOfDay.Text Then
SoundAlarm()
MsgBox("wake up!")
End If
Private Sub SoundAlarm()
Dim SAPI
SAPI = CreateObject("sapi.spvoice
If BeepingToolStripMenuItem1.
My.Computer.Audio.Play(My.
MusicToolStripMenuItem1.Ch
SpeechToolStripMenuItem.Ch
End If
If MusicToolStripMenuItem1.Ch
My.Computer.Audio.Play(My.
BeepingToolStripMenuItem1.
SpeechToolStripMenuItem.Ch
End If
If SpeechToolStripMenuItem.Ch
SAPI.Speak(txtEnterWords.T
MusicToolStripMenuItem1.Ch
BeepingToolStripMenuItem.C
End If
End Sub
Then in my if statement is this:
If lblAlarmTime.Text = lblTimeOfDay.Text Then
SoundAlarm()
MsgBox("wake up!")
End If
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
no other understandable solutions were offered
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