External ActiveX components, i.e. applications that run in their own window outside of SAP GUI, or even without any visible window, can be invoked with the VBScript standard function "CreateObject". For communication with GuiXT, in addition to parameter passing and returning a value in the VBScript function, we can use a special object "guixt". It is automatically created by GuiXT before the VBScript function is called. Among others, the "guixt" object possesses the following methods:

  • guixt.get() and guixt.set() to set and get the content of a GuiXT script variable V[xxx]

  • guixt.getText() and guixt.setText() to set and get the content of a GuiXT long text variable text[....]

We will discuss further methods of the "guixt" object in later tutorials.

As an example of how to invoke an external ActiveX component we implement a spelling check for a GuiXT textbox, using MS Word. The user enters a text into the textbox within the SAP GUI transaction and then clicks a button "Spell check". This starts the MS Word application and performs an interactive spell check during which the user can correct  misspelled words. The corrected text is updated in the GuiXT textbox.

Our GuiXT script creates a textbox and a pushbutton, surrounded with a group box:

Box (15,1) (26,72) "Text (Demo GuiXT Controls)"
Textbox
(16,1) (24,72) name="iwtext"
Pushbutton
(25,2) "Spell check" process=
"spellcheck.txt"

This looks as follows:

The InputScript "spellcheck.txt" calls a VBScript function "spellcheck", passing the name of the GuiXT long text whose content is to be checked, in our case this is "iwtext":

CallVBS msg = spellcheck "iwtext"

if
V[msg]
  Message
"E: &V[msg]" -statusline
else
  Message
"S: Spell check done" -statusline
endif

The VBScript function changes the long text "iwtext" via the MS Word spell check. In case of a technical problem, for example if MS Word is not installed on the PC, the VBScript function returns an error text.

Communication with the Word Application is complex since MS Word offers a very rich object model with many attributes and methods. It is always recommendable in such cases to search the internet for a similar task and a sample program that can often be found for commonly used controls such as Word or Excel.

Our VBScript function "spellcheck" creates the "Word.Application" object and copies the GuiXT long text into the Word document. We then call the built-in interactive spell check of MS Word. With the corrected text we update the GuiXT long text variable. At this point we have to take into consideration that Word uses CR (carriage return) at the end of each line, but the GuiXT textbox requires "CRLF" (carriage return plus linefeed). We use the command Replace(doc.Content.Text, vbCr, vbCrLf)in order to keep the line structure of the text.

Function spellcheck(txtname)

    ' MS Word application
    dim myWord 
    
    OnErrorResumeNext
      Set myWord = CreateObject("Word.Application")
    OnErrorGoto0
            
    IfIsEmpty(myWord) Then
        spellcheck = "Sorry - MS Word not installed"
        ExitFunction
    EndIf
    
    Call myWord.Resize(400,300)
    myWord.Caption = "Spell checking"
    
    myWord.Visible = True
    
    dim doc
    Set doc = myWord.Documents.Add
    doc.Activate
    
    doc.Content.Text =  guixt.getText("iwtext")
    
    doc.CheckSpelling
    
    Call guixt.setText("iwtext", Replace(doc.Content.Text, vbCr, vbCrLf))          
        
    doc.Saved = False
    doc.Close (0)
    
    Set doc = Nothing
    myWord.Quit
    Set myWord = Nothing
    
    spellcheck = ""
    
EndFunction

The whole feature from the user's point of view:

The user writes a text and then clicks the "Spell check" button.

In case of misspelled words the Word spell check window comes up and presents correction proposals. The user performs the correction interactively and the corrected text is finally updated in the GuiXT textbox: