4 Replies - 718 Views - Last Post: 09 April 2012 - 01:30 PM Rate Topic: -----

#1 Glorfindal  Icon User is offline

  • Java Enthusiast
  • member icon

Reputation: 23
  • View blog
  • Posts: 538
  • Joined: 31-December 08

[Solved] Converting A String to an Array and then using it as an array

Posted 07 April 2012 - 11:54 AM

Okay I am working on a Voice Recognition Application that has a chat bot in it. When voice is recognized it converts the recognized string into an array and checks if the first or last value of the array is either computer or the Bot's Name. However, I am still very new to VB.NET only been programming in it for a few days. (I know ASP and VBscript really well though) When it goes through the check I get an exception how do I fix this? Here's my code with a comment on the line that it fails on:

    Private Sub OnReco(ByVal StreamNumber As Integer, ByVal StreamPosition As Object, ByVal RecognitionType As SpeechRecognitionType, ByVal Result As ISpeechRecoResult) Handles RecoContext.Recognition
        Dim recoResult As String = Result.PhraseInfo.GetText 'Create a new string, and assign the recognized text to it.
        Dim VoiceArray
        Dim VoiceArray2
        Dim VoiceString
        VoiceArray = Split(recoResult)
        If LBound(VoiceArray) = "computer" Or LBound(VoiceArray) = BotName Then 'It gives an exception on this line
            VoiceArray2 = Filter(VoiceArray, "computer")
            VoiceArray2 = Filter(VoiceArray, BotName)
            VoiceString = Join(VoiceArray2, " ")
            Dim SpeechEngine = CreateObject("Sapi.Spvoice")
            Dim MyRequest As New Request(VoiceString, MyUser, MyBot)
            Dim MyResult = MyBot.Chat(MyRequest)
            RichTextBox1.AppendText("[YOU]: " & TextBox3.Text & vbNewLine & "[BOT]: " & MyResult.Output & vbNewLine)
            TextBox3.Text = ""
            SpeechEngine.Speak(MyResult.Output)
        End If
        If UBound(VoiceArray) = "computer" Or UBound(VoiceArray) = BotName Then 'I suspect if it continued there would be an exception on this line aswell
            VoiceArray2 = Filter(VoiceArray, "computer")
            VoiceArray2 = Filter(VoiceArray, BotName)
            VoiceString = Join(VoiceArray2, " ")
            Dim SpeechEngine = CreateObject("Sapi.Spvoice")
            Dim MyRequest As New Request(VoiceString, MyUser, MyBot)
            Dim MyResult = MyBot.Chat(MyRequest)
            RichTextBox1.AppendText("[YOU]: " & TextBox3.Text & vbNewLine & "[BOT]: " & MyResult.Output & vbNewLine)
            TextBox3.Text = ""
            SpeechEngine.Speak(MyResult.Output)
        End If
    End Sub


Thanks in advance.

This post has been edited by Glorfindal: 09 April 2012 - 01:31 PM


Is This A Good Question/Topic? 0
  • +

Replies To: [Solved] Converting A String to an Array and then using it as an array

#2 Ionut  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 385
  • View blog
  • Posts: 1,057
  • Joined: 17-July 10

Re: [Solved] Converting A String to an Array and then using it as an array

Posted 07 April 2012 - 12:06 PM

It would be helpfull if you could tell us the error as well.
As a first glance, I see that you compare an integer value(LBound returns the lowest index of an array - in this case I think it is 0) to a string value -> "computer". if you want to get the first value of an array, that should be :
VoiceArray[0] = "computer"
'or
VoiceArray[LBound(VoiceArray)] 


Although I wouldn't use LBound and UBound in .NET(these are VB6/VBS operators). In .NET an array starts from 0 and goes to array.Length - 1(length is a property) and then you can easily play with indices
Was This Post Helpful? 0
  • +
  • -

#3 Glorfindal  Icon User is offline

  • Java Enthusiast
  • member icon

Reputation: 23
  • View blog
  • Posts: 538
  • Joined: 31-December 08

Re: [Solved] Converting A String to an Array and then using it as an array

Posted 07 April 2012 - 12:16 PM

Yeah that was the error but now I am getting an "Identifier Expected" error. Here is code:
        If VoiceArray[0] = "computer" Or VoiceArray[0] = BotName Then 'Still the Same Line
            VoiceArray2 = Filter(VoiceArray, "computer")
            VoiceArray2 = Filter(VoiceArray, BotName)
            VoiceString = Join(VoiceArray2, " ")
            Dim SpeechEngine = CreateObject("Sapi.Spvoice")
            Dim MyRequest As New Request(VoiceString, MyUser, MyBot)
            Dim MyResult = MyBot.Chat(MyRequest)
            RichTextBox1.AppendText("[YOU]: " & TextBox3.Text & vbNewLine & "[BOT]: " & MyResult.Output & vbNewLine)
            TextBox3.Text = ""
            SpeechEngine.Speak(MyResult.Output)
        End If


Was This Post Helpful? 0
  • +
  • -

#4 Ionut  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 385
  • View blog
  • Posts: 1,057
  • Joined: 17-July 10

Re: [Solved] Converting A String to an Array and then using it as an array

Posted 07 April 2012 - 12:38 PM

Change
VoiceArray[0]



with
VoiceArray(0)


Was This Post Helpful? 1
  • +
  • -

#5 Glorfindal  Icon User is offline

  • Java Enthusiast
  • member icon

Reputation: 23
  • View blog
  • Posts: 538
  • Joined: 31-December 08

Re: [Solved] Converting A String to an Array and then using it as an array

Posted 09 April 2012 - 01:30 PM

Thanks that fixed it! +1 to you! :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1