I am making a chatter bot and having issues with to many else if

  • (2 Pages)
  • +
  • 1
  • 2

16 Replies - 1704 Views - Last Post: 03 August 2013 - 07:52 AM Rate Topic: -----

#1 cjawood  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 13-April 11

I am making a chatter bot and having issues with to many else if

Posted 13 April 2011 - 05:35 PM

Hi,
I like vb6 and have being working on building a robot, I want to add voice reconition and speach.
I found some code for a chatterbot and want to add to it some more.
but....
If i add 10000 lines of ElseIf 's
in my module code.
It crashes saying "Procedure to large".
Does anyone know how i could add these ElseIf's into a text file to look for the key words?

Thanks





ElseIf InStr(strQuestion, "good-night") Then
strAnswer = "good night, hope to talk to you later."
AnsFound = True

ElseIf InStr(strQuestion, "why") Then
strAnswer = "why what?"
AnsFound = True
LogQuestion

ElseIf InStr(strQuestion, "what!") Then
strAnswer = "I didn't stu-stu-stutter!"
AnsFound = True
LogQuestion

ElseIf InStr(strQuestion, "what") Then
strAnswer = "This is the best I can think of for that."
AnsFound = True
LogQuestion

Else
    strAnswer = "I'm afraid I don't understand what you have"
    LogQuestion
    End If
End If
AnsFound = True

ElseIf InStr(strQuestion, "are you") Then
strAnswer = "I don't know right now"
AnsFound = True

ElseIf InStr(strQuestion, "i am") Or InStr(strQuestion, "i'm") Then
strAnswer = "I'm sorry, I'm not sure what you are"
AnsFound = True
LogQuestion

ElseIf InStr(strQuestion, "shit") Then
strAnswer = "you do have a foul mouth"
AnsFound = True

ElseIf strQuestion = "hi" Then
strAnswer = "Hi, welcome to the session."
AnsFound = True

ElseIf InStr(strQuestion, "howdy") Then
strAnswer = "Hi, welcome to the session."
AnsFound = True

ElseIf InStr(strQuestion, "hey") Then
strAnswer = "what? what's up?"
AnsFound = True


Is This A Good Question/Topic? 0
  • +

Replies To: I am making a chatter bot and having issues with to many else if

#2 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 303
  • View blog
  • Posts: 1,797
  • Joined: 26-March 09

Re: I am making a chatter bot and having issues with to many else if

Posted 14 April 2011 - 03:24 AM

If it's always one question = one answer, then you could add them into a text file as delimited pairs (separated by a delimiter, so question;answer for example on each line).

There is a code snippet on reading in text files, so have a look at that.

You could store the results in a collection, using the question as the key, then you can query the collection by the key for the answer.

That should give you some starting points.
Was This Post Helpful? 0
  • +
  • -

#3 guyfromri  Icon User is offline

  • D.I.C Addict

Reputation: 46
  • View blog
  • Posts: 829
  • Joined: 16-September 09

Re: I am making a chatter bot and having issues with to many else if

Posted 14 April 2011 - 07:23 AM

I would try using

Select Case

End Select


Was This Post Helpful? 0
  • +
  • -

#4 cjawood  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 13-April 11

Re: I am making a chatter bot and having issues with to many else if

Posted 14 April 2011 - 05:18 PM

Thanks for the idea, I'll look into trying to figure that out.
Was This Post Helpful? 0
  • +
  • -

#5 cjawood  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 13-April 11

Re: I am making a chatter bot and having issues with to many else if

Posted 14 April 2011 - 05:25 PM

One problem is that I already have a text file with many many
ElseIf Questions and answers, but to many I guess.
Could a person make alot of modules and have the program look at them?
How could I look to see if "answer not found" then have it look at the next module?
Is that possible?
Thanks much
Was This Post Helpful? 0
  • +
  • -

#6 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 303
  • View blog
  • Posts: 1,797
  • Joined: 26-March 09

Re: I am making a chatter bot and having issues with to many else if

Posted 15 April 2011 - 02:36 AM

you wouldn't store the elseif type code in a text file, only the data, and there should be no issue with the size of a datafile.

If you look into the suggestion I made, it will do what you want.
Was This Post Helpful? 1
  • +
  • -

#7 cjawood  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 13-April 11

Re: I am making a chatter bot and having issues with to many else if

Posted 15 April 2011 - 04:08 PM

Thanks,
Might be some dirty stuff in it but,I added my text file for people that might want it..
I didn't make all the questions and answer's.

Attached File(s)


This post has been edited by cjawood: 15 April 2011 - 04:17 PM

Was This Post Helpful? 0
  • +
  • -

#8 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: I am making a chatter bot and having issues with to many else if

Posted 16 April 2011 - 04:02 PM

maj's suggestion is much more efficient than this, although I would also look into the Dictionary object. Also, you have some elseifs there that will never get hit.
Was This Post Helpful? 0
  • +
  • -

#9 Jeeves  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 03-August 13

Re: I am making a chatter bot and having issues with to many else if

Posted 03 August 2013 - 05:06 AM

I am new to this forum but after reading your question I have some sample code that may help.

Private Sub DirectSR1_PhraseFinish(ByVal flags As Long, _
ByVal beginhi As Long, ByVal beginlo As Long, ByVal endhi As Long, _
ByVal endlo As Long, ByVal Phrase As String, ByVal parsed As String, _
ByVal results As Long)

Dim replyfiletext As String

Case "How are you"
    'SendKeys "How are you"
    lblReply.Caption = "How are you"
    Open App.Path & "\okreply.txt" For Input As #1
Input #1, replyfiletext
lblReply.Caption = replyfiletext
AC.Speak replyfiletext
AC.Speak "How are you,, today"
On Error Resume Next
Close #1


For each question asked you can have a text file with several answers to the same question.
If you use the Random statement you can have it cycle through that text file and read a single line of text.
While this code does not show the use of the random statement I am sure with some research you can find out how to use it.

Almost forgot to add, put this on you load form event.


DirectSR1.GrammarFromFile App.Path & "\Words.txt"
DirectSR1.Activate

Agent1.Characters.Load "Merlin", "Merlin.acs"
Agent1.Characters.Character("Merlin").Balloon.Visible = False
    Set AC = Agent1.Characters("Merlin")
    AC.Show

Was This Post Helpful? 0
  • +
  • -

#10 cjawood  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 13-April 11

Re: I am making a chatter bot and having issues with to many else if

Posted 03 August 2013 - 05:30 AM

Thanks,
I will check into it, in the winter time most likely.
Still haven't finished the body all the way so I'm not worried about this yet.
Thanks for the reply
Was This Post Helpful? 0
  • +
  • -

#11 Jeeves  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 03-August 13

Re: I am making a chatter bot and having issues with to many else if

Posted 03 August 2013 - 05:54 AM

This may get you going a little sooner.
I designed an Assistive Companion (robot) that will follow commands and retains a record of its movements so they can be repeated.
Here is a picture for you, next is a arm to be designed and added.

Attached image(s)

  • Attached Image

Was This Post Helpful? 0
  • +
  • -

#12 andrewsw  Icon User is offline

  • It's just been revoked!
  • member icon

Reputation: 3833
  • View blog
  • Posts: 13,580
  • Joined: 12-December 12

Re: I am making a chatter bot and having issues with to many else if

Posted 03 August 2013 - 06:05 AM

@Jeeves
You've just posted your code that in another forum you say is not working :whistling:

http://www.dreaminco...0&#entry1883939

This post has been edited by andrewsw: 03 August 2013 - 06:06 AM

Was This Post Helpful? 0
  • +
  • -

#13 Jeeves  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 03-August 13

Re: I am making a chatter bot and having issues with to many else if

Posted 03 August 2013 - 06:10 AM

You are correct to some point.
It works so long as it is used in a small way but when extended to hundreds of works/ phrases it has a problem.
Was This Post Helpful? 0
  • +
  • -

#14 Jeeves  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 03-August 13

Re: I am making a chatter bot and having issues with to many else if

Posted 03 August 2013 - 06:30 AM

I revoke my previous answer, it has some problems even with just three case and three replies.
Please do not use right now.
Was This Post Helpful? 0
  • +
  • -

#15 Jeeves  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 03-August 13

Re: I am making a chatter bot and having issues with to many else if

Posted 03 August 2013 - 07:35 AM

View Postcjawood, on 15 April 2011 - 04:08 PM, said:

Thanks,
Might be some dirty stuff in it but,I added my text file for people that might want it..
I didn't make all the questions and answer's.


Can you provide a copy of the full project.
I might have an answer to you problem/question.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2