AI Zone Admin Forum Add your forum

NEWS: Chatbots.org survey on 3000 US and UK consumers shows it is time for chatbot integration in customer service!read more..

Creating a Chatbot in VB/Access - Where do I Start?
 
 
  [ # 16 ]

I know only PHP well, to be honest, and unless you want to use your chatbot via a web browser, that’s not the best platform to use. And if you don’t mind using a web browser, then there’s already a PHP-based solution available: Program O.

 

 
  [ # 17 ]
Asir Pinarbasi - Dec 13, 2013:

Can I do it in Python than? Perhaps, you can help me than…

http://nltk.org/api/nltk.chat.html

As for VBA you’ll have to play around with MS Access.  I think you could have good results. Of course you would want to use the Access database, right? If I remember correctly, maybe someone remembers, the MSAccess file is self contained, meaning your chatbot could live in that database file… But you have to check on that.  I think VBScript and regular expressions may be worth a look too.

Set Regex CreateObject("vbscript.regexp"
 

 
  [ # 18 ]

There are probably one of two ways to go.

The first, you’ve already demonstrated with your VB code.  Although crude, with enough IF THEN rules, you can code a fairly decent bot.  Mind you, it will take a lot of time (like with any bot), and your IF statements will become long.

On the the other hand, you mentioned Access.  Access is a *horrible* database, but for the sake of a school project, it’s ok.  Using access, you could create a simple table with input and response fields, and populate it with all the rules you’d like the bot to respond do.  Then using VB, you could query the access database.

Now sadly I can not help you with the VB code, but with some Googling you should be able to find enough sample code to show you how to create an ODBC connection to an access database, and how to run simple SQL queries against it.

I did a similar project with Perl and mySQL, and it actually worked reasonably well.

 

 
  [ # 19 ]

Thank you for your help. But I don’t know the ‘‘tricks’’ to do those things. Could someone help me please?

 

 
  [ # 20 ]

Have you read this MSDN forum yet?

Link: Need Help Creating a Chat Bot in Visual Basic 2010 or Visual Web Developer Express

 

 
  [ # 21 ]

I have shared the following with Asir:

Create a simple Chatbot in Microsoft Access in 1 hour (divided into 15 tasks). 

This is for people who already have some knowledge of Access and who are interested in creating their own chatbot in VBA.  The following will show how you can create a SIMPLE chatbot in short while and will get you started.  It is not the best way (I recommend checking out ChatScript elsewhere on these forums).  It is not the fastest or the most efficient chatbot.  We will not be using Class modules but will use a module for custom types.  There most likely will be typos and possible mistakes and I am sure there is a “better” way.  I welcome your feedback and suggestions.  On to task 1…

 

 
  [ # 22 ]

Task   1. Add a table.  Call it “tblBrainPatterns”.  Add three fields. 
        a. PatternNum as Long Integer. 
        b. Pattern as Short Text (i.e. String of 255 characters)
        c. Response as Short Text (i.e. String of 255 characters)
        d. Add data to the table by entering statements and questions you want your chabot to respond to under “Pattern” and enter the chatbots repsonses under “Response”.  Number the rows sequentially 1,2,3, etc.  The field does not need to be an autoid as you may want to edit the numbers later, but the row numbers should be unique.
                    i. Example: PatternNum=1, Pattern=”Bye”, Response=”Goodbye”
                    ii. Example: PatternNum=2, Pattern=”How are you?”, Response=”I am fine.”

 

 
  [ # 23 ]

Task 2.  Add a new blank form. Call it “frmChatbot”. Switch to Design View. Add two textboxes.
        a. Edit the first textbox label to display “Chat History:”.  Under the textbox propertes make the name of the     textbox “txtChatHistory”.  In the GUI editor just drag the bottom of the textbox so that it is about 20 rows high (on mine it is height: 3.7813”).  It does not really matter as long as it is tall enough to display multiple rows of chat history which you can specify later.  On the Property Sheet, under the “Data” tab, set the “Locked” property to yes so users cannot edit this field.  On the Property Sheet, under the “Other” tab, set the “Tab Index” property to zero and “Tab Stop” property to “false”.
        b. Edit the second textbox label to display “Say:”  Under the textbox propertes make the name of the textbox “txtChat”.  Leave the height of the textbox a single line.
        c. Add a button.  Just click finish immmediatly and exit the wizard.  If it has an image delete it under properties. Change the caption under properties to say “Enter”.  Make the name “cmdEnter”.  Place the button after the txtChat textbox to the right.

 

 
  [ # 24 ]

Task 3. Now the next part is a little tricky if you have not done this before.  You need to add a “Module”. 
        a. Select “Create” on the menu bar.  On the ribbon select “Module” (it should be on the far upper right of the ribbon).  Do not select “Class Module”.  Select just the plain “Module” option. 
        b. Cut and past the following code to create two custom types. 

      Option Compare Database

      Type TypeBrainPattern
      PatternNum As Integer
      Pattern As String
      Response As String
      End Type

      Type TypeBrain
      MyName As String
      IQ As Integer
      CurrentThought As TypeBrainPattern
      YourName As String
      AppropriateResponse As String
      End Type

      c. On the bottom left pane there should be the property (Name) displayed followed by “Module1”. Change “Module1” to “modCustomTypes”

 

 
  [ # 25 ]

Task 4. Add logic to run when the form loads:
      a. Open the form “frmChatbot” again in design view.  Click on the upper left box to select the form or select “Form” the Property Sheet control dropdown.  Go to the “Event” tab on the Property Sheet and click inside of the blank box to the right of the “On Load” event.  Click the “…” button to the right.  Choose “Code Builder” from the popup.  This takes you to the code behind your form.  Replace the blank sub routine for the onload event with the following code:

Private Sub Form_Load()

  Resurrect (“Watson Jr.”)
  Me.Form.Caption = Brain.MyName
  InitializeChatHistory
  Say (“Hi.”)
  Brain.YourName = “Stranger”
 
End Sub

 

 
  [ # 26 ]

Task 5.

Add header information and declare objects whose scope is form-wide.  The array “BrainPatterns”, custom type “Brain”, constant “ChatHistoryMaxRows” and array “ChatHistory” will persist across sub routines and functions without having to be passed as parameters or by reference.  “Option base 1” will start your arrays at 1 instead of 0.

      a. Scroll to the top of your form code and replace any header rows with the following:

Option Compare Database
Option Explicit
Option Base 1

Dim BrainPatterns() As TypeBrainPattern
Dim Brain As TypeBrain
Const ChatHistoryMaxRows As Integer = 20
Dim ChatHistory(ChatHistoryMaxRows) As String

 

 
  [ # 27 ]

Task 6.

Close the code window and go back to the form in design view and select the button.  Under events in the property sheet select the “On Click” event.  Select the “…” button.  Choose “Code Design” form the pop-up.  Replace the code for the on click event with the following:

Private Sub cmdEnter_Click()

  ReplyTo (Me.txtChat)

End Sub

 

 
  [ # 28 ]

Task 7. Now we resurrect our chatbot and give it its name!

      a. Cut and paste the following code into the bottom of the code for the form.  You can always get back to your form code by selecting design from the top menu bar and then “View Code” which display on the far right of the ribbon.

Private Sub Resurrect(ChatBotName As String)

  Brain.MyName = ChatBotName
  LoadBrainPatterns

End Sub

 

 
  [ # 29 ]

Task   8. Now we need to fill the empty brain with the BrainPatterms that you spent all of that time entering into the table “tblBrainPatterns”.  This is somewhat of a pain in Access as you need to load it into a recordset first and then into an array.  This is where the custom types make it a little easier to understand but all you really need to do is cut and paste the following code into your form’s code:

Private Sub LoadBrainPatterns()

  Dim rstBrainPatterns As DAO.Recordset
  Dim Thought As Integer
  Set rstBrainPatterns = CurrentDb.OpenRecordset(“tblBrainPatterns”)
 
  If Not rstBrainPatterns.EOF Then
 
      rstBrainPatterns.MoveFirst
      Brain.IQ = rstBrainPatterns.RecordCount
      ReDim BrainPatterns(Brain.IQ)
      Thought = 1
 
      Do Until rstBrainPatterns.EOF
        With BrainPatterns(Thought)
        .PatternNum = rstBrainPatterns(“PatternNum”)
        .Pattern = rstBrainPatterns.Fields(“Pattern”)
        .Response = rstBrainPatterns.Fields(“Response”)
        Thought = Thought + 1
        rstBrainPatterns.MoveNext
        End With
      Loop
 
  End If
 
  If IsObject(rstBrainPatterns) Then Set rstBrainPatterns = Nothing

End Sub

 

 
  [ # 30 ]

Task 9. Now that we have knowledge loaded in the form of an array or BrainPatterns we can work on replying.  Copy the following code into your form’s code:

Private Sub ReplyTo(WhatWasSaid)

  Brain.AppropriateResponse = “Huh?”
  ThinkHardAbout (WhatWasSaid)
  Say (Brain.AppropriateResponse)

End Sub

 

 < 1 2 3 > 
2 of 3
 
  login or register to react