|
Please sign our guestbook! |
|
You can also attach a VBScript program to any given phrase (or word) so that it's triggered when the phrase is used in a question. Each script is given a single word name, which is also the name of the function in the script to run when the script is triggered. This function can call other functions defined in the same Script panel. The return value of the function will be used as a replacement for the trigger phrase.
To get started with this feature, you can write a simple script:
Now try adding a line to the Phrases list (ABC on the Toolbar). This shows how you can make phrase replacements completely interactive. Of course, you might want to program an advanced system that makes substitutions based on the circumstances. Here's a slightly more useful example:
When I Type: [my accounts]    Script: MyAccounts
(both functions must go into the same script panel) Function Accounts      If UserID = "BobG" then          Accounts = "the Smith accounts"      Else          Accounts = "the Jones accounts"      End If End Function Function MyAccounts      MyAccounts = Accounts End Function We've provided some useful information to get you started. Within any script, you can reference the following: (Note: this section incorporates v2.1 modifications.)
' Public Properties
' Public Methods
The Question is what's typed into the query box. PrivateErrorCode is used to pass an error code from a script triggered by a Question or a Phrase to another script that is triggered after the translation SQL is produced (an Answer script). SQL is the SQL translation and can be read only by Answer scripts. QueryResult is the numeric code for the processing result. To display a custom error message, set this value to -8 in your script and set the ErrorMessage variable as follows: "Error Message I Want Displayed;Optional Header for the Error Message" Execution Error codes can occur during SQL Server 7.0 processing -7 indicates numeric overflow; -8 indicates a timeout error. SpellCheck scripts will trigger both before and (optionally) after popping up our spell-check window. The SpellCheckOut variable holds "?" if the script is triggered before, otherwise it holds the correction. You might want to intercept some common spelling errors and simply replace them without bothering the user with a pop-up window. To do this, set the SpellCheckOut value to the word you want to replace (the mis-spelled word is available in SpellCheckIn). If you do this, the pop-up window won't . . . SpellCheck scripts also trigger AFTER the pop-up window closes. The main purpose of this is to avoid a security hole. For example, lets say you write a Question Script which detects questions like "Show the sex of employees." The security script might deal with this by just setting the PrivateErrorCode to -8 with a error message explaining that this information is not published. You don't want a hacker-type to then simply type in "Show the seZx of employees." and use the spell-corrector (which fires after the Question script) to subvert the security system. If a SpellCheck script fires and SpellCheckOut is NOT "?" then it's the correction the user selected from the pop-up window. You can then inspect that to make sure it's not one of your proscribed terms. To see exactly what's going on with script processing, you can set the Debug Script flag on, which will show you the input and output of each script every time it fires. The most important use of scripts has been left for last. Until now, there were only manual methods for switching between Views. Views are ELF interfaces, defined on a particular set of related tables. Although it's extremely useful to narrow the selection of tables to improve interface accuracy, this has not been popular in the past -- because it required the user to select the proper View. Not anymore! Question Scripts can choose the View that should be used to answer any given question, after it's typed in. For example, you could use the UserID and any keywords you find in the Question to decide to answer the question with View X instead of View Y. Or use anything else you can program in VB -- for instance, the time of day (Now() function). The result returned by a Question script should be the name of a valid View (if you return nothing, for instance using the script to modify or validate the question, then the currently selected View is used). The Methods are provided as a way for your scripts to directly set the operative View, without returning a value from your function. The reason you might want to do this is in order to reset the PATH where grammars (.ELF subdirectories) are located, at the same time you shift Views. To change the path, use the SetDirectoryPath method. For instance, SetDirectoryPath f:\applications\elf\grammars Now your function can return the name of a View located in that directory. Alternatively, you can set the View yourself, for instance: result = OpenView("MyFavoriteView") The result is True is successful, False if not. Including the OpenView method seems redundant at first glance, since you can set the View by returning its name from your script. The one case in which it's not redundant is if you have multiple Views with the same name located in different directories. If you switch directories and return the name, VB ELF will see that the name hasn't changed, so it won't reload the grammar.In that case, you'd need to use the OpenView function directly. As they say, the uses are limited only by your imagination. To quote FireSign Theatre, we think this is "a power so great it can only be used for good or evil." (Note: to change the scripting language from VBScript to JScript, open the VBELF.MDA database and change the elfScriptingLanguage entry of the elfDefaults table to "JScript".) Please see the section on What's New in Version 2.1 for a description of enhancements made to the scripting components. These include the ability to create script-function libraries (via use of #include commands), and the introduction of data-aware triggers (passed into PhraseScripts).
Last Updated: November, 1999 |