1. Welcome to TechPowerUp Forums, Guest! Please check out our forum guidelines for info related to our community.

vb.net events not firing

Discussion in 'Programming & Webmastering' started by shuggans, May 6, 2013.

  1. shuggans

    Joined:
    Dec 22, 2007
    Messages:
    175 (0.07/day)
    Thanks Received:
    7
    Location:
    Central Nebraska
    Ive created an event in my code, however the sub I created to handle the event is not firing - any ideas o nthe code below?

    Code:
    Imports System.Speech.Recognition
    Public Class Form1
    
        Public Shared Recognizer As SpeechRecognizer
        Public Event LoadGrammarCompleted As EventHandler(Of LoadGrammarCompletedEventArgs)
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Recognizer = New SpeechRecognizer
            Dim dictation As Grammar = New DictationGrammar
            Recognizer.LoadGrammar(dictation)
    
        End Sub
        Public Sub LoadGrammar(ByVal sender As Object, ByVal e As LoadGrammarCompletedEventArgs) Handles MyClass.LoadGrammarCompleted
            MessageBox.Show("Bing!")
        End Sub
    
    End Class
     
  2. FordGT90Concept

    FordGT90Concept "I go fast!1!11!1!"

    Joined:
    Oct 13, 2008
    Messages:
    13,726 (6.24/day)
    Thanks Received:
    3,633
    Location:
    IA, USA
    Last edited: May 6, 2013
    Crunching for Team TPU
  3. shuggans

    Joined:
    Dec 22, 2007
    Messages:
    175 (0.07/day)
    Thanks Received:
    7
    Location:
    Central Nebraska
    loadgrammarcompleted looks for sender as obect and e as system.speech.recognition.loadgrammarcompletedeventargs

    I cant find what it's looing for. Ive tried me, e and get an error saying "Unable to cast object of type 'system.eventargs' to type 'system.speech.recognition.loadgrammarcompletedeventargs.'"
     
  4. FordGT90Concept

    FordGT90Concept "I go fast!1!11!1!"

    Joined:
    Oct 13, 2008
    Messages:
    13,726 (6.24/day)
    Thanks Received:
    3,633
    Location:
    IA, USA
    You have to call New LoadGrammarCompletedEventArgs() most likely and make sure to give it what it requires.

    I don't know what code you're working with but perhaps you aren't supposed to raise the event at all, it does. You just need to start whatever process in that library that would raise it (a .Start() or something).

    Also, the Recognition code should have the event, not your form. Your form needs to hook into its event, not create a new one.
     
    Crunching for Team TPU

Currently Active Users Viewing This Thread: 1 (0 members and 1 guest)

Share This Page