none
case RRS feed

  • Question

  •  the first case has an error "expression does not produce a value" I can't figure out how to fix this.
     Select Case e.Result.Text = "Hi"
                Case My.Computer.Audio.Play(My.Resources.A,
                         AudioPlayMode.WaitToComplete)
    
                Case Else
                    My.Computer.Audio.Play(My.Resources.B,
                         AudioPlayMode.WaitToComplete)
            End Select


    Donny


    Monday, August 7, 2017 9:23 PM

Answers

  • Donny,

    What event handler is that?

    Show the rest of it please.


    "A problem well stated is a problem half solved.” - Charles F. Kettering

    Monday, August 7, 2017 9:33 PM
  • Check the syntax and try this:

    Select Case e.Result.Text
       Case "Hi"
          . . .
    Case "Hello"
    . . . Case Else . . . End Select


    Monday, August 7, 2017 10:52 PM
  • Donny,

    Comment out all of your code and put in the word "Stop" in that sub. When the program stops there, hover your mouse over "e".

    See what's going on now?

    Select Case is a conditional test, just like an "If" is so the compile error you saw is right.

    Make sense?


    "A problem well stated is a problem half solved.” - Charles F. Kettering

    Tuesday, August 8, 2017 12:06 AM
  • Scott,

    I see Frank always using the stop. Therefore: you can also click the F9 to make a temporally stop. (Before versions 2017 there were more friendly ways but for whatever reason they have removed that)

    Also try to use VB code. It is in many things the same as C# but especially if it is about handling of events superior to C#. (Many C# programmers have begged to get that as parity in C#)

    Imports System.Speech.Recognition
    
    Public Class Form1
        Private gram As Grammar
        Private WithEvents recoge As New SpeechRecognizer
        Private wordlist As String() = New String() {"Hi", "Hello", "Goodbye", "Bye", "What is your name", "Who are you"}
        ' word recognised event
        Public Sub recevent(ByVal sender As System.Object, ByVal e As RecognitionEventArgs) Handles recoge.SpeechRecognized
            If e.Result.Text = "Hi" Then

    For the rest my is my message the same as Frank wrote. Debug it. 

    I wanted to reply you already yesterday. But my message was not accepted. Frank was one second before me.


    Success
    Cor


    Tuesday, August 8, 2017 8:22 AM
  • Hi Scott746525255,

    About error message that you provided, I think there may be no a return value in My.Computer.Audio.Play(My.Resources.A, AudioPlayMode.WaitToComplete), you may have some error in select.

     Select Case e.Result.Text
                Case "Hi"
                    My.Computer.Audio.Play(My.Resources.A,
                         AudioPlayMode.WaitToComplete)
                Case "Hello"
                    My.Computer.Audio.Play(My.Resources.HEllo_sir,
                          AudioPlayMode.WaitToComplete)
                Case "Goodbye"
                    My.Computer.Audio.Play(My.Resources.Good_bye_sir,
                              AudioPlayMode.WaitToComplete)
                    Me.Close()
                Case "Bye"
                    My.Computer.Audio.Play(My.Resources.Good_bye_sir,
                           AudioPlayMode.WaitToComplete)
                    Me.Close()
                Case "What is your name"
                    My.Computer.Audio.Play(My.Resources.NAME,
                            AudioPlayMode.WaitToComplete)
                Case "Who are you"
                    My.Computer.Audio.Play(My.Resources.NAME,
                           AudioPlayMode.WaitToComplete)
                Case Else
                    Return
            End Select

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Tuesday, August 8, 2017 8:33 AM
    Moderator

All replies

  • Donny,

    What event handler is that?

    Show the rest of it please.


    "A problem well stated is a problem half solved.” - Charles F. Kettering

    Monday, August 7, 2017 9:33 PM
  • Check the syntax and try this:

    Select Case e.Result.Text
       Case "Hi"
          . . .
    Case "Hello"
    . . . Case Else . . . End Select


    Monday, August 7, 2017 10:52 PM
  • Here is the entire program.
    Imports System.Speech.Recognition
    Imports System.Threading
    Imports System.Globalization
    Imports System.IO
    Public Class Form1
        ' recogniser & grammar
    
        Dim gram As Grammar
        Dim recoge As New SpeechRecognizer
    
        ' events
        Public Event SpeechRecognized As  _
            EventHandler(Of SpeechRecognizedEventArgs)
        Public Event SpeechRecognitionRejected As  _
            EventHandler(Of SpeechRecognitionRejectedEventArgs)
        ' word list
        Dim wordlist As String() = New String() {"Hi", "Hello", "Goodbye", "Bye", "What is your name", "Who are you"}
        ' word recognised event
        Public Sub recevent(ByVal sender As System.Object,
                ByVal e As RecognitionEventArgs)
            If e.Result.Text = "Hi" Then
                My.Computer.Audio.Play(My.Resources.A,
                          AudioPlayMode.WaitToComplete)
    HERE IT IS>>>>  Select Case e.Result.Text = "Hi"
                   Case My.Computer.Audio.Play(My.Resources.B,
                           AudioPlayMode.WaitToComplete)
    
                    Case Else
                'My.Computer.Audio.Play(My.Resources.Hi_sir_how_are_you,
                '                  AudioPlayMode.WaitToComplete)
                'End Select
            End If
            If (e.Result.Text = "Hello") Then
                My.Computer.Audio.Play(My.Resources.HEllo_sir,
                          AudioPlayMode.WaitToComplete)
    
            End If
            If (e.Result.Text = "Goodbye") Then
                My.Computer.Audio.Play(My.Resources.Good_bye_sir,
                              AudioPlayMode.WaitToComplete)
                Me.Close()
            End If
            If (e.Result.Text = "Bye") Then
                My.Computer.Audio.Play(My.Resources.Good_bye_sir,
                           AudioPlayMode.WaitToComplete)
                Me.Close()
            End If
            If (e.Result.Text = "What is your name") Then
                My.Computer.Audio.Play(My.Resources.NAME,
                             AudioPlayMode.WaitToComplete)
            End If
            If (e.Result.Text = "Who are you") Then
                My.Computer.Audio.Play(My.Resources.NAME,
                             AudioPlayMode.WaitToComplete)
            End If
    
        End Sub
        ' recognition failed event
        Public Sub recfailevent(ByVal sender As System.Object,
                ByVal e As RecognitionEventArgs)
            My.Computer.Audio.Play(My.Resources.D_underst,
                            AudioPlayMode.WaitToComplete)
    
        End Sub
        ' form initialisation
        Private Sub Form1_Load(ByVal sender As System.Object,
                ByVal e As System.EventArgs) Handles MyBase.Load
            Timer1.Start()
            Timer2.Start()
            DoubleBuffered = True
            If TimeOfDay.ToString.Contains("AM") Then
                If TimeOfDay.Hour.ToString <= ("6") Then
                    My.Computer.Audio.Play(My.Resources.Bed,
                            AudioPlayMode.WaitToComplete)
                End If
                If TimeOfDay.Hour.ToString >= ("6") Then
                    My.Computer.Audio.Play(My.Resources.Good_morning,
                            AudioPlayMode.WaitToComplete)
                End If
            End If
            If TimeOfDay.ToString.Contains("PM") Then
                If TimeOfDay.Hour.ToString >= ("6") Then
                    My.Computer.Audio.Play(My.Resources.G_eve,
                             AudioPlayMode.WaitToComplete)
                End If
                If TimeOfDay.Hour.ToString <= ("6") Then
                    My.Computer.Audio.Play(My.Resources.G_afternoon,
                             AudioPlayMode.WaitToComplete)
                End If
            End If
    
            ' need these to get British English rather than default US
            Thread.CurrentThread.CurrentCulture = New CultureInfo("en-GB")
            Thread.CurrentThread.CurrentUICulture = New CultureInfo("en-GB")
            ' convert the word list into a grammar
            Dim words As New Choices(wordlist)
            gram = New Grammar(New GrammarBuilder(words))
            recoge.LoadGrammar(gram)
            ' add handlers for the recognition events
            AddHandler recoge.SpeechRecognized, AddressOf Me.recevent
            AddHandler recoge.SpeechRecognitionRejected, AddressOf Me.recfailevent
            ' enable the recogniser
            recoge.Enabled = True
            Try
            Catch recoge As Exception
    
            End Try
            Try
            Catch recoge As Exception
    
            End Try
            Try
    
            Catch speech As Exception
    
            End Try
        End Sub
    
    
        Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
            If Me.Opacity = 1 Then
                Timer1.Enabled = False
            Else
                Me.Opacity = Me.Opacity + 0.1
            End If
    
        End Sub
    
       
      
    End Class



    Donny


    Monday, August 7, 2017 11:15 PM
  • Donny,

    Comment out all of your code and put in the word "Stop" in that sub. When the program stops there, hover your mouse over "e".

    See what's going on now?

    Select Case is a conditional test, just like an "If" is so the compile error you saw is right.

    Make sense?


    "A problem well stated is a problem half solved.” - Charles F. Kettering

    Tuesday, August 8, 2017 12:06 AM
  • Scott,

    I see Frank always using the stop. Therefore: you can also click the F9 to make a temporally stop. (Before versions 2017 there were more friendly ways but for whatever reason they have removed that)

    Also try to use VB code. It is in many things the same as C# but especially if it is about handling of events superior to C#. (Many C# programmers have begged to get that as parity in C#)

    Imports System.Speech.Recognition
    
    Public Class Form1
        Private gram As Grammar
        Private WithEvents recoge As New SpeechRecognizer
        Private wordlist As String() = New String() {"Hi", "Hello", "Goodbye", "Bye", "What is your name", "Who are you"}
        ' word recognised event
        Public Sub recevent(ByVal sender As System.Object, ByVal e As RecognitionEventArgs) Handles recoge.SpeechRecognized
            If e.Result.Text = "Hi" Then

    For the rest my is my message the same as Frank wrote. Debug it. 

    I wanted to reply you already yesterday. But my message was not accepted. Frank was one second before me.


    Success
    Cor


    Tuesday, August 8, 2017 8:22 AM
  • Hi Scott746525255,

    About error message that you provided, I think there may be no a return value in My.Computer.Audio.Play(My.Resources.A, AudioPlayMode.WaitToComplete), you may have some error in select.

     Select Case e.Result.Text
                Case "Hi"
                    My.Computer.Audio.Play(My.Resources.A,
                         AudioPlayMode.WaitToComplete)
                Case "Hello"
                    My.Computer.Audio.Play(My.Resources.HEllo_sir,
                          AudioPlayMode.WaitToComplete)
                Case "Goodbye"
                    My.Computer.Audio.Play(My.Resources.Good_bye_sir,
                              AudioPlayMode.WaitToComplete)
                    Me.Close()
                Case "Bye"
                    My.Computer.Audio.Play(My.Resources.Good_bye_sir,
                           AudioPlayMode.WaitToComplete)
                    Me.Close()
                Case "What is your name"
                    My.Computer.Audio.Play(My.Resources.NAME,
                            AudioPlayMode.WaitToComplete)
                Case "Who are you"
                    My.Computer.Audio.Play(My.Resources.NAME,
                           AudioPlayMode.WaitToComplete)
                Case Else
                    Return
            End Select

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Tuesday, August 8, 2017 8:33 AM
    Moderator