External activeX
components that run outside of the SAP GUI window as independent
applications can be called and managed with VB.NET standard tools.
As an example for using an external activeX component we implement a
spelling check for a GuiXT textBox using Microsoft Word. The user types
in a long text and can trigger the spell check with a pushbutton. We
then start a word application, pass the text and call the spell check.
The user can correct the text which will then be transferred to the GuiXT
textbox automatically.
The GuiXT
script creates a textbox, a pushbutton and a group frame for
these two elements:
Box
(15,1)
(26,72)
"Text (Demo GuiXT Controls)"
Textbox
(16,1)
(24,72)
name="iwtext"
Pushbutton
(25,2)
"Spell check"
process="spellcheck.txt"
It looks
like this:
The
InputScript "spellcheck.txt" calls a VB.NET function "spellcheck" and
passes the name, "iwtext", of the GuiXT longtext that we want checked:
CallVB msg = utilities.class1.spellcheck
"iwtext"
if
V[msg=ok]
Message
"S: Spellcheck ok"
-statusline
else
Message
"E: &V[msg]"
-statusline
endif
Return
The VB.NET
function alters the longtext "iwtext" via the word spell checker. If any
technical error occurs, e.g. MS word is not installed on this PC, the
VB.NET functions returns an error message.
We create the
"word" object and then copy the GuiXT long text into the document. After
that we call the interactive spell checker. The corrected text is put
back into the GuiXT text variable, whereby line breaks can cause trouble.
This can be avoided by replacing all occurences of CR by CRLF:
Word only returns CR at the end of a line (carriage return), but the
textbox needs CRLF (carriage return + line feed):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55 | Imports guinet
Imports Microsoft.Office.Interop
Public Class Class1
Function spellcheck(ByVal txtname As String) As String
Dim myguixt = New guixt
Dim mytext = myguixt.GetText("iwtext")
Dim myWord As Word.Application
' MS Word application
Try
myWord = CreateObject("Word.Application")
Catch ex As Exception
Return "Sorry - MS Word not installed"
End Try
If myWord Is Nothing Then
Return "Sorry - MS Word not installed"
End If
' text ok?
If myWord.CheckSpelling(mytext) Then
myWord.Quit()
Return "ok"
End If
myWord.WindowState = Word.WdWindowState.wdWindowStateMaximize
myWord.Caption = "Spell checking"
myWord.Visible = True
Dim doc As Word.Document
doc = myWord.Documents.Add
doc.Activate()
doc.Content.Text = mytext
doc.CheckSpelling()
myguixt.SetText("iwtext", Replace(doc.Content.Text, vbCr, vbCrLf))
doc.Close(SaveChanges:=False)
myWord.Quit()
Return ""
End Function
End Class
|
Sequence
of events for the user:
The user
writes some text and then pushes the spell check button:
If there are spelling mistakes a word window pops up displaying
correction
proposals. The user can accept them and the altered text will be
transferred to the GuiXT textbox automatically:
|