Form S_198FA: Control Word through ActiveX

LANSA

Form S_198FA: Control Word through ActiveX
* ===================================================================
*
* Component : S_198FA
* Type : Form
* Ancestor : PRIM_FORM
*
* Description : Control Word through ActiveX
*
* Disclaimer : The following material is supplied as sample material
* only. No warranty concerning this material or its use
* in any way whatsoever is expressed or implied.
*


*
* Component : S_198FA
* Type : Form
* Ancestor : PRIM_FORM
*
* Description : Control Word through ActiveX
*
* Disclaimer : The following material is supplied as sample material
* only. No warranty concerning this material or its use
* in any way whatsoever is expressed or implied.
*
* ===================================================================
FUNCTION OPTIONS(*DIRECT)
BEGIN_COM CAPTION('Controlling Microsoft Word with ActiveX ') FORMPOSITION(ScreenCenter) HEIGHT(371) LEFT(191) TOP(55) WIDTH(714)
DEFINE_COM CLASS(#VA_WORD.Application) NAME(#WordApp) REFERENCE(*DYNAMIC)

DEFINE_COM CLASS(#PRIM_PHBN) NAME(#STARTBTN) CAPTION('Start Word') DISPLAYPOSITION(1) HEIGHT(20) LEFT(16) PARENT(#GPBX_2) TABPOSITION(1) TOP(24) WIDTH(105)
DEFINE_COM CLASS(#PRIM_PHBN) NAME(#NEWBTN) CAPTION('New...') DISPLAYPOSITION(1) ENABLED(False) HEIGHT(20) LEFT(16) PARENT(#GPBX_4) TABPOSITION(1) TOP(24) WIDTH(113)
DEFINE_COM CLASS(#PRIM_PHBN) NAME(#PRINTBTN) CAPTION('Print') DISPLAYPOSITION(2) ENABLED(False) HEIGHT(20) LEFT(16) PARENT(#GPBX_4) TABPOSITION(2) TOP(240) WIDTH(113)
DEFINE_COM CLASS(#PRIM_PHBN) NAME(#SAVEBTN) CAPTION('Save ...') DISPLAYPOSITION(4) ENABLED(False) HEIGHT(20) LEFT(16) PARENT(#GPBX_4) TABPOSITION(4) TOP(216) WIDTH(113)
DEFINE_COM CLASS(#PRIM_GPBX) NAME(#GPBX_1) CAPTION('Word WindowState') DISPLAYPOSITION(3) ENABLED(False) HEIGHT(81) LEFT(16) PARENT(#GPBX_2) TABPOSITION(3) TABSTOP(False) TOP(72) WIDTH(113)
DEFINE_COM CLASS(#PRIM_RDBN) NAME(#RDBN_1) CAPTION('Minimized') DISPLAYPOSITION(1) ENABLED(False) LEFT(15) PARENT(#GPBX_1) TABPOSITION(1) TOP(14) WIDTH(82)
DEFINE_COM CLASS(#PRIM_RDBN) NAME(#RDBN_2) BUTTONCHECKED(True) CAPTION('Normal') DISPLAYPOSITION(2) ENABLED(False) LEFT(16) PARENT(#GPBX_1) TABPOSITION(2) TOP(32) WIDTH(89)
DEFINE_COM CLASS(#PRIM_RDBN) NAME(#RDBN_3) CAPTION('Maximized') DISPLAYPOSITION(3) ENABLED(False) LEFT(16) PARENT(#GPBX_1) TABPOSITION(3) TOP(50) WIDTH(81)
DEFINE_COM CLASS(#PRIM_GPBX) NAME(#GPBX_2) CAPTION('Word Application') DISPLAYPOSITION(1) HEIGHT(193) LEFT(0) PARENT(#COM_OWNER) TABPOSITION(1) TABSTOP(False) TOP(8) WIDTH(137)
DEFINE_COM CLASS(#PRIM_GPBX) NAME(#GPBX_4) CAPTION('Documents') DISPLAYPOSITION(2) HEIGHT(297) LEFT(144) PARENT(#COM_OWNER) TABPOSITION(2) TABSTOP(False) TOP(8) WIDTH(145)
DEFINE_COM CLASS(#PRIM_PHBN) NAME(#CLOSEBTN) CAPTION('Close') DISPLAYPOSITION(3) ENABLED(False) HEIGHT(20) LEFT(16) PARENT(#GPBX_4) TABPOSITION(3) TOP(264) WIDTH(113)
DEFINE_COM CLASS(#PRIM_LTVW) NAME(#LTVW_1) DISPLAYPOSITION(5) ENABLED(False) HEIGHT(129) LEFT(16) PARENT(#GPBX_4) TABPOSITION(5) TOP(80) WIDTH(113)
DEFINE_COM CLASS(#PRIM_PHBN) NAME(#SHOWHIDEBTN) CAPTION('Show/Hide Word') DISPLAYPOSITION(2) ENABLED(False) HEIGHT(20) LEFT(16) PARENT(#GPBX_2) TABPOSITION(2) TOP(48) WIDTH(105)
DEFINE_COM CLASS(#PRIM_STBR) NAME(#STBR_1) DISPLAYPOSITION(3) HEIGHT(25) LEFT(0) MESSAGEPOSITION(1) PARENT(#COM_OWNER) TABPOSITION(3) TOP(319) WIDTH(706)
DEFINE_COM CLASS(#PRIM_PHBN) NAME(#EXITBTN) CAPTION('Exit Word') DISPLAYPOSITION(4) ENABLED(False) HEIGHT(20) LEFT(16) PARENT(#GPBX_2) TABPOSITION(4) TOP(160) WIDTH(105)
DEFINE_COM CLASS(#PRIM_PHBN) NAME(#OPENBTN) CAPTION('Open...') DISPLAYPOSITION(6) ENABLED(False) HEIGHT(20) LEFT(16) PARENT(#GPBX_4) TABPOSITION(6) TOP(48) WIDTH(113)
DEFINE_COM CLASS(#PRIM_GPBX) NAME(#GPBX_5) CAPTION('Insert Table ') DISPLAYPOSITION(1) ENABLED(False) HEIGHT(81) LEFT(200) PARENT(#GPBX_6) TABPOSITION(1) TABSTOP(False) TOP(168) WIDTH(185)
DEFINE_COM CLASS(#PRIM_SPDT) NAME(#COLUMNS) DISPLAYPOSITION(1) ENABLED(False) HEIGHT(20) LEFT(88) PARENT(#GPBX_5) TABPOSITION(1) TOP(22) VALUE(1) WIDTH(41)
DEFINE_COM CLASS(#PRIM_SPDT) NAME(#ROWS) DISPLAYPOSITION(2) ENABLED(False) HEIGHT(20) LEFT(136) PARENT(#GPBX_5) TABPOSITION(2) TOP(22) VALUE(1) WIDTH(41)
DEFINE_COM CLASS(#PRIM_LABL) NAME(#LABL_1) CAPTION('Columns/rows:') DISPLAYPOSITION(3) ENABLED(False) HEIGHT(24) LEFT(8) PARENT(#GPBX_5) TABPOSITION(3) TABSTOP(False) TOP(22) WIDTH(73)
DEFINE_COM CLASS(#PRIM_GPBX) NAME(#GPBX_6) CAPTION('Active Document') DISPLAYPOSITION(4) ENABLED(False) HEIGHT(297) LEFT(296) PARENT(#COM_OWNER) TABPOSITION(4) TABSTOP(False) TOP(8) WIDTH(401)
DEFINE_COM CLASS(#PRIM_GPBX) NAME(#GPBX_3) CAPTION('Insert Text') DISPLAYPOSITION(2) ENABLED(False) HEIGHT(145) LEFT(200) PARENT(#GPBX_6) TABPOSITION(2) TABSTOP(False) TOP(16) WIDTH(185)
DEFINE_COM CLASS(#PRIM_MEMO) NAME(#MEMO_1) ADDENTRYMODE(MultiplePerLine) CURRENTLINE(1) DISPLAYPOSITION(1) ENABLED(False) HEIGHT(89) HORIZONTALSCROLL(False) LEFT(8) MAXIMUMLINELENGTH(10000) ONOUTPUT(AddLineFeed) PARENT(#GPBX_3) TABPOSITION(1) TOP(16) WIDTH(169) WORDWRAP(True)
DEFINE_COM CLASS(#PRIM_PHBN) NAME(#INSTXTBTN) CAPTION('Insert Text') DISPLAYPOSITION(2) ENABLED(False) HEIGHT(20) LEFT(96) PARENT(#GPBX_3) TABPOSITION(2) TOP(112)
DEFINE_COM CLASS(#PRIM_PHBN) NAME(#INSTABBTN) CAPTION('Insert Table') DISPLAYPOSITION(4) ENABLED(False) HEIGHT(20) LEFT(96) PARENT(#GPBX_5) TABPOSITION(4) TOP(50)
DEFINE_COM CLASS(#PRIM_PHBN) NAME(#VIEWHTMLBTN) CAPTION('View as HTML') DISPLAYPOSITION(3) ENABLED(False) HEIGHT(20) LEFT(208) PARENT(#GPBX_6) TABPOSITION(3) TOP(256) WIDTH(81)
DEFINE_COM CLASS(#PRIM_GPBX) NAME(#GPBX_7) CAPTION('Position Cursor To ') DISPLAYPOSITION(4) ENABLED(False) HEIGHT(265) LEFT(8) PARENT(#GPBX_6) TABPOSITION(4) TABSTOP(False) TOP(16) WIDTH(185)
DEFINE_COM CLASS(#PRIM_LABL) NAME(#LABL_3) CAPTION('Line:') DISPLAYPOSITION(1) ENABLED(False) HEIGHT(20) LEFT(14) PARENT(#GPBX_7) TABPOSITION(1) TABSTOP(False) TOP(16) WIDTH(33)
DEFINE_COM CLASS(#PRIM_LABL) NAME(#LABL_4) CAPTION('Page:') DISPLAYPOSITION(2) ENABLED(False) HEIGHT(27) LEFT(14) PARENT(#GPBX_7) TABPOSITION(2) TABSTOP(False) TOP(40) WIDTH(33)
DEFINE_COM CLASS(#PRIM_SPDT) NAME(#LINENO) DISPLAYPOSITION(3) ENABLED(False) HEIGHT(20) LEFT(48) PARENT(#GPBX_7) TABPOSITION(3) TOP(16) VALUE(1) WIDTH(49)
DEFINE_COM CLASS(#PRIM_SPDT) NAME(#PAGENO) DISPLAYPOSITION(4) ENABLED(False) HEIGHT(20) LEFT(48) PARENT(#GPBX_7) TABPOSITION(4) TOP(40) VALUE(1) WIDTH(49)
DEFINE_COM CLASS(#PRIM_LTVW) NAME(#LTVW_2) DISPLAYPOSITION(5) ENABLED(False) FULLROWSELECT(True) HEIGHT(145) LEFT(24) PARENT(#GPBX_7) TABPOSITION(5) TOP(72) WIDTH(137)
DEFINE_COM CLASS(#PRIM_PHBN) NAME(#GOTOBMBTN) CAPTION('Go to Bookmark') DISPLAYPOSITION(6) ENABLED(False) HEIGHT(20) LEFT(24) PARENT(#GPBX_7) TABPOSITION(6) TOP(232) WIDTH(137)
DEFINE_COM CLASS(#PRIM_LVCL) NAME(#LVCL_2) CAPTION('Docum') DISPLAYPOSITION(1) PARENT(#LTVW_1) SOURCE(#S_198DOC) WIDTH(98) WIDTHTYPE(Remainder)
DEFINE_COM CLASS(#PRIM_MECL) NAME(#MECL_1) COLUMNROLE(Data) DISPLAYPOSITION(1) PARENT(#MEMO_1) SOURCE(#S_198TXT) WIDTH(20) WIDTHTYPE(Remainder)
DEFINE_COM CLASS(#PRIM_LVCL) NAME(#LVCL_1) DISPLAYPOSITION(1) PARENT(#LTVW_2) SOURCE(#S_198BM) WIDTH(20) WIDTHTYPE(Remainder)
DEFINE_COM CLASS(#PRIM_PHBN) NAME(#GOTOLINEBTN) CAPTION('Go to Line') DISPLAYPOSITION(7) ENABLED(False) HEIGHT(20) LEFT(104) PARENT(#GPBX_7) TABPOSITION(7) TOP(16) WIDTH(65)
DEFINE_COM CLASS(#PRIM_PHBN) NAME(#GOTOPAGEBTN) CAPTION('Go to Page') DISPLAYPOSITION(8) ENABLED(False) HEIGHT(20) LEFT(104) PARENT(#GPBX_7) TABPOSITION(8) TOP(40) WIDTH(65)

* Define a component definition for fiedl #I so that it's value property can be used as index in collections
DEFINE_COM CLASS(#STD_NUM) NAME(#I)
*create a component definition for field S_198BM so that it can hadle Word parameters of type variant (string/number)
DEFINE_COM CLASS(#S_198BM) NAME(#S_198BM)
DEFINE_COM CLASS(#PRIM_PHBN) NAME(#VIEWNORMALBTN) CAPTION('View Normal') DISPLAYPOSITION(5) ENABLED(False) HEIGHT(20) LEFT(296) PARENT(#GPBX_6) TABPOSITION(5) TOP(256)

EVTROUTINE HANDLING(#COM_OWNER.Initialize) OPTIONS(*NOCLEARMESSAGES *NOCLEARERRORS)
* set #STD_BOOL false because Word is not visible
change #STD_BOOL False
ENDROUTINE

EVTROUTINE HANDLING(#STARTBTN.Click)
*Start Word by setting a reference to it. Word has been enrolled as ActiveX component S_WORD
SET_REF COM(#WordApp) TO(*CREATE_AS #va_word.application)

*If Word has been started, enable some controls and issue a message
if_ref com(#wordapp) is_not(*null)
execute enable10
execute infmessage 'Word has been started.'
endif
ENDROUTINE

EVTROUTINE HANDLING(#showhidebtn.Click)
*If Word is hidden make it visible and vice versa
if cond('#wordapp.visible *eq True')
change #STD_BOOL False
SET #WordApp Visible(false)
else
SET #WordApp Visible(true)
change #STD_BOOL True
endif
ENDROUTINE

EVTROUTINE HANDLING(#RDBN_1.Click)
*Set the size of the Word window using the Windowstate property of the Word application object.
IF COND('#rdbn_1.buttonchecked *eq true')
SET #WordApp Windowstate(va_WORD.wdWindowStateMinimize)
endif
ENDROUTINE

EVTROUTINE HANDLING(#RDBN_2.Click)
if cond('#rDbn_2.buttonchecked *eq True')
SET #WordApp Windowstate(va_WORD.wdWindowStateNormal)
endif
ENDROUTINE

EVTROUTINE HANDLING(#RDBN_3.Click)
if cond('#rdbn_3.buttonchecked *eq True')
SET #WordApp Windowstate(va_WORD.wdWindowStateMaximize)
endif
ENDROUTINE

EVTROUTINE HANDLING(#EXITBTN.Click)
* Close Word without saving any changes
invoke method(#WordApp.Quit) savechanges(0)
*
*Clear lists and disable controls in the Work with Document group box
clr_list #ltvw_1

*issue a message and disable controls
execute infmessage 'Word has been closed.'
execute disable10
execute disable20
ENDROUTINE

EVTROUTINE HANDLING(#NEWBTN.Click)
*Show the Word New Document dialog
invoke method(#WordApp.Dialogs.item<va_Word.wdDialogFileNew>.show) SHOW_Retval(#std_num)
*
if cond('#std_num *ne 0')
*Enable and show controls, show message
execute enable20
execute infmessage 'A new document has been opened.'

*Update the list of documents
execute doclist
endif
ENDROUTINE

EVTROUTINE HANDLING(#OPENBTN.Click)
*Show the Word Open Document dialog
invoke method(#WordApp.Dialogs.item<va_Word.wdDialogFileOpen>.show) SHOW_Retval(#std_num)
*
execute ShowHide

if cond('#std_num *ne 0')
*Enable and show controls, show message
execute enable20
execute infmessage 'Document has been opened.'

*Update the list of documents
execute doclist
endif
ENDROUTINE

EVTROUTINE HANDLING(#ltvw_1.ItemGotFocus)
*activate the selected document
invoke method(#wordapp.documents.item<#s_198doc>.activate)
ENDROUTINE

evtroutine handling(#wordapp.documentchange)
*get bookmarks in the active document
if cond('#WordApp.Documents.Count *gt 0')
execute bmlist
endif
endroutine

EVTROUTINE HANDLING(#PRINTBTN.Click)
*Print out the document.
invoke method(#WordApp.ActiveDocument.PrintOut)
execute infmessage 'Document has been sent to the printer.'
ENDROUTINE

EVTROUTINE HANDLING(#SAVEBTN.Click)
*Bring up the Save dialog
invoke method(#WordApp.Dialogs.item<va_Word.wdDialogFileSaveAs>.show) SHOW_Retval(#std_num)
if cond('#std_num *ne 0')
*update document list
execute doclist
execute infmessage 'Document has been saved.'
endif
execute ShowHide
ENDROUTINE

EVTROUTINE HANDLING(#CLOSEBTN.Click)
*if a document is open, close it without saving any changes
if cond('#WordApp.Documents.Count *gt 0')
invoke method(#wordapp.activedocument.close) savechanges(0)
endif

*update document list, issue a message, disable controls
execute doclist
execute infmessage 'Document has been closed.'
execute disable20
ENDROUTINE

SUBROUTINE NAME(DOCLIST)
***Get document names and put them in a list
*get the number of open Word documents
change #std_num #WordApp.Documents.Count
*Clear #ltvw_1 and then add the names of all open documents
clr_list #ltvw_1
begin_loop using(#i) FROM(1) TO(#std_num)
change #s_198DOC #wordapp.documents.item<#i.value>.name_COM
add_entry #ltvw_1
end_loop
endroutine

subroutine bmlist
***Get the bookmarks in the document and put them in a list
*get the number of bookmarks
change #std_count #WordApp.ActiveDocument.Bookmarks.Count

clr_list #ltvw_2
if cond('#std_count *gt 0')
*Clear #ltvw_2 and then add bookmark names
begin_loop using(#i) FROM(1) TO(#std_count)
set com(#s_198BM) value(#WordApp.ActiveDocument.Bookmarks.item<#i.value>.name_COM)
add_entry #ltvw_2
end_loop
else
change #s_198BM 'No bookmarks'
add_entry #ltvw_2
endif
endroutine

* Go to a line
EVTROUTINE HANDLING(#GoToLineBtn.Click)
*Get the number of lines in the document and if the line exists, move the cursor to it
Invoke method(#WordApp.ActiveDocument.ComputeStatistics) Statistic(va_Word.wdStatisticLines) ComputeStatistics_RETVAL(#std_num)
if cond('(#LineNo.Value *le #Std_num) *AND (#LineNo.Value *gt 0)')
* Go to a line
invoke method(#WordApp.Selection.GoTo) what(3) which(1) count(#LineNo.Value)
execute infmessage 'The cursor has been moved to the line.'
else
execute infmessage 'This line does not exist in the document.'
endif
ENDROUTINE

* Go to a page
EVTROUTINE HANDLING(#GoToPageBtn.Click)
*Get the number of pages in the document and if the page exists, move the cursor to it
Invoke method(#WordApp.ActiveDocument.ComputeStatistics) Statistic(va_Word.wdStatisticPages) ComputeStatistics_RETVAL(#std_num)
if cond('(#PageNo.Value *le #Std_num) *AND (#PageNo.Value *gt 0)')
* Go to a page
invoke method(#WordApp.Selection.GoTo) what(3) which(1) count(#PageNo.Value)
execute infmessage 'The cursor has been moved to the page.'
else
execute infmessage 'This page does not exist in the document.'
endif

ENDROUTINE

* Move cursor to selected bookmark
EVTROUTINE HANDLING(#GoToBmBtn.Click)
invoke method(#WordApp.ActiveDocument.Bookmarks.item<#S_198BM.value>.select)

execute infmessage 'Boomark is selected.'
ENDROUTINE

* Insert the text in the multiline edit box
EVTROUTINE HANDLING(#INSTXTBTN.Click)
invoke method(#WordApp.Selection.TypeText) text(#Memo_1.outputtext)
clr_list #memo_1
set #memo_1 characterPosition(0)
execute infmessage 'Text has been inserted.'
ENDROUTINE

* Insert a blank table
EVTROUTINE HANDLING(#INSTABBTN.Click)

if cond('(#Columns.Value *gt 0) *AND (#Rows.Value *gt 0)')
invoke method(#WordApp.ActiveDocument.Tables.Add) Range(#WordApp.Selection.Range) NumRows(#Rows.value) NumColumns(#Columns.value)
execute infmessage 'Table has been inserted.'
else
execute infmessage 'Row and column number must be greater than 0'
endif
ENDROUTINE

* Control the minimum value of spin boxes
EVTROUTINE HANDLING(#LINENO.Changed) OPTIONS(*NOCLEARMESSAGES *NOCLEARERRORS)
if '#lineno.value < 1'
set #lineno value(1)
endif
ENDROUTINE

* View the document as HTML
EVTROUTINE HANDLING(#VIEWHTMLBTN.Click)
set com(#WordApp.ActiveWindow.ActivePane.view) Type(va_Word.wdWebView)
SET #WordApp Visible(True)
ENDROUTINE

* View the document in normal view
EVTROUTINE HANDLING(#VIEWNormalBtn.Click)
set com(#WordApp.ActiveWindow.ActivePane.view) Type(va_Word.wdNormalView)
SET #WordApp Visible(True)
ENDROUTINE

* Enable controls after Word has been started
subroutine name(Enable10)
set com(#showhidebtn #gpbx_1 #rdbn_1 #rdbn_2 #rdbn_3 #newbtn #openbtn #exitbtn ) enabled(true)
endroutine

* Enable controls when there is an active document
subroutine name(Enable20)
if cond('#WordApp.Documents.Count *ne 0')
set com(#ltvw_1 #savebtn #printbtn #closebtn) enabled(true)
set com(#gpbx_3 #gpbx_5 #gpbx_6 #gpbx_7 #instxtbtn #memo_1 #columns #instabbtn #labl_1 #rows) enabled(true)
set com(#gotobmbtn #gotolinebtn #gotopagebtn #labl_1 #labl_3 #labl_4 #lineno #ltvw_2 #pageno #viewhtmlbtn #viewnormalbtn) enabled(true)
endif
endroutine

* Disable controls after Word has been closed
subroutine name(Disable10)
set com(#showhidebtn #gpbx_1 #rdbn_1 #rdbn_2 #rdbn_3 #newbtn #openbtn #labl_1 #exitbtn ) enabled(false)
endroutine

*Disable controls when there is no active document
subroutine name(Disable20)
if cond('#WordApp.Documents.Count *eq 0')
clr_list #ltvw_2
set com(#ltvw_1 #savebtn #printbtn #closebtn) enabled(false)
set com(#gpbx_3 #gpbx_5 #gpbx_6 #gpbx_7 #instxtbtn #memo_1 #columns #instabbtn #labl_1 #rows) enabled(false)
set com(#gotobmbtn #gotolinebtn #gotopagebtn #labl_1 #labl_3 #labl_4 #lineno #ltvw_2 #pageno #viewhtmlbtn #viewnormalbtn) enabled(false)
endif
endroutine

* Hide or show Word
subroutine ShowHide
if cond('#std_bool *eq True')
SET #WordApp Visible(True)
else
SET #WordApp Visible(False)
endif
endroutine

* Information Message created by template VL_BBSTSBR
SUBROUTINE INFMESSAGE ((#EX_TEXT *RECEIVED))
define #ex_text *char 132
message msgid(dcm9993) msgf(dc@m01) msgdta(#ex_text *blanks)
ENDROUTINE

END_COM