Author Topic: Interfacing with Hal's brain with COM/ActiveX  (Read 633 times)


  • Administrator
  • Hero Member
  • *****
  • Posts: 1240
    • View Profile
Interfacing with Hal's brain with COM/ActiveX
« on: December 18, 2016, 11:00:49 pm »
If you want to interface with Hal's brain from an external project and can utilize COM/ActiveX here are some code samples in VB6 and VB.NET. C# would be very similar to the version.

Here's the full code how to make a command line version of Hal in VB.NET:

Code: [Select]
Option Strict Off
Option Explicit On

Module modHalConsole

    'Constants that point to path of script to run and database to open
    Const HalScript As String = "C:\Program Files\Zabaware\Ultra Hal Assistant 6\Hal6.uhp"
    Const HalDB As String = "C:\Program Files\Zabaware\Ultra Hal Assistant 6\HalBrain.db"

    'Objects that will contain reference to HalBrain and WordNet activex dll
    Dim HalBrain As Object
    Dim WN As Object

    'Variants to hold contents of Hal's short term memory
    Dim GainControl, PrevUserSent, PrevSent, Insults, Hate, Swear, Compliment, LastResponseTime, CustomMem, LastTopicList As Object

    Sub Main()

        Dim HalScriptControl As New MSScriptControl.ScriptControl
        Dim HalCommands As Object
        Dim ScriptOut As String
        Dim PassVars(14) As Object

        'Create instance of HalBrain and WordNet ActiveX DLL
        HalBrain = CreateObject("UltraHalAsst6.Brain")
        WN = CreateObject("UltraHalAsst6.WordNet")

        'Initialize Hal's memory

        'Read script file and add to script control, open database connection
        Dim ff As Short
        Dim TheScript As String
        ff = FreeFile()
        FileOpen(ff, HalScript, OpenMode.Input)
        TheScript = InputString(ff, LOF(ff))
        HalScriptControl.AllowUI = True
        HalScriptControl.Language = "VBScript"
        HalScriptControl.Timeout = 10000
        HalScriptControl.UseSafeSubset = False
        HalScriptControl.AddObject("HalBrain", HalBrain, True) 'Give script control access to HalBrain object
        HalScriptControl.AddObject("WN", WN, True) 'Give script control access to WN object
        HalBrain.OpenDatabase(HalDB) 'Open database

            'Load up object array with variant function paramaters script is expecting
            PassVars(0) = Console.ReadLine()
            PassVars(1) = "Judge"
            PassVars(2) = "Steve"
            PassVars(3) = 0 'Learning
            PassVars(4) = HalDB
            PassVars(5) = Hate
            PassVars(6) = Swear
            PassVars(7) = Insults
            PassVars(8) = Compliment
            PassVars(9) = PrevSent
            PassVars(10) = LastResponseTime
            PassVars(11) = PrevUserSent
            PassVars(12) = CustomMem
            PassVars(13) = GainControl
            PassVars(14) = LastTopicList

            'Run Script
            ScriptOut = HalScriptControl.Run("UltraHal", PassVars)

            'If script was successfull it will contain <STOREVARS> in which case we remember the variables passed and extract the response
            If InStr(ScriptOut, "<STOREVARS>") Then
                ScriptOut = HalBrain.RecallVars(ScriptOut, HalCommands, Hate, Swear, Insults, Compliment, PrevSent, LastResponseTime, PrevUserSent, CustomMem, GainControl, LastTopicList)
            End If



    End Sub

    Sub ResetMem()
        Hate = 0
        Swear = 0
        Insults = 0
        Compliment = 0
        PrevSent = ""
        LastResponseTime = ""
        PrevUserSent = ""
        CustomMem = ""
        GainControl = ""
        LastTopicList = ""
    End Sub

End Module
Robert Medeksza


  • Sr. Member
  • ****
  • Posts: 345
  • The Mighty Hal Machine
    • View Profile
    • Ultra Hal Plugin Shop
Re: Interfacing with Hal's brain with COM/ActiveX
« Reply #1 on: December 19, 2016, 11:14:34 am »
we off to the races man,,,,,
in a big way too, My brain is on fire again after so many years. and as it would be,  VB too, better then sex.

I am truely honored



  • Sr. Member
  • ****
  • Posts: 345
  • The Mighty Hal Machine
    • View Profile
    • Ultra Hal Plugin Shop
Re: Interfacing with Hal's brain with COM/ActiveX
« Reply #2 on: December 22, 2016, 04:48:06 pm »
Many thanx again Robert: Most of this goes beyond my skill sets at the moment,lol,MOMENT. But the Job was very professionally Rem'd.

In truth that is, many 1000'a of dollars of coding classes.

Thanx for the freebee

Anything i can do to help in the sales of Hal,dont hesitate too ask,Im steady pushing Hal any way. I know of at-least 04 pple that have downloaded the time trial. Version. It aint much but its a few Bucks.

best wishes
« Last Edit: January 05, 2017, 12:25:37 pm by cyberjedi »


  • Sr. Member
  • ****
  • Posts: 357
    • View Profile
Re: Interfacing with Hal's brain with COM/ActiveX
« Reply #3 on: December 29, 2016, 11:59:21 pm »
cool 8) thanks.
be informed and always vote it will help you in the long run does not matter if your liberal, conservative or independent. stay informed and watch the votes in government not what the media tells you.