S_208RMW

LANSA

S_208RMW
* ===================================================================
*
* Component : S_208RMW
* Type : Reusable Component
* Ancestor : PRIM_PANL
*
* Description : Handle the extraction of bookmarked values from a
* MS-Word document and pass the details extracted back
* to S_208FMF.
*
* Disclaimer : The following material is supplied as example material
* only. No warranty concerning this material or its use
* in any way whatsoever is expressed or implied.
*
* ===================================================================
FUNCTION OPTIONS(*DIRECT)
BEGIN_COM DISPLAYPOSITION(1) HEIGHT(34) LEFT(0) TABPOSITION(1) TOP(0) WIDTH(62)

* MS-Word Object Definitions

DEFINE_COM CLASS(#VA_WORD.Application) NAME(#APPLICATION) Reference(*Dynamic)
DEFINE_COM CLASS(#VA_WORD.Document) NAME(#DOCUMENT) Reference(*Dynamic)
DEFINE_COM CLASS(#VA_WORD.BookMark) NAME(#BookMark) Reference(*Dynamic)

* The event that signals document information back to S_208FMF

Define_Evt InformationFound
Define_Map *input #s_208Name #WithName
Define_Map *input #s_208Aval #WithValue

* -------------------------------------------------------------
* Handle an information extraction request coming from S_208FMF
* -------------------------------------------------------------

MthRoutine ExtractInformation
Define_Map *input #SysVar$av #FromDocument

* Loop and other temporary variable definitions

Define #A_Limit Reffld(#Std_Num)
Define #A_Index Reffld(#Std_Num)
Define #MarkIndex Reffld(#Std_Num)

* Create the MS-Word application if it does not already exist

If_Ref #Application is(*null)

Set_Ref #Application (*Create_as #VA_WORD.Application)

* Minimize the window containing MS-Word

Change #Std_Num 2
Set #Application WindowState(#Std_Num)

Endif

* Open the MS-Word document

Invoke #Application.Documents.Open FileName(#FromDocument.Value) Open_RETVAL(#Document)

* If the MS-Word document was opened

If_ref #Document is_not(*null)

* Now extract the bookmarked details and feed their values back to
* S_208FMF by issuing multiple "InformationFound" signals. S_208FMF
* listens for these signals, reformats the names and values passed
* and then stores the information in a series of working lists (ready
* to pass on to the AS/400 server for processing).

* Get a count of the number of bookmarked values

Change #A_Limit #Document.BookMarks.Count

* Loop through all bookmarked values and pass the associated
* symbolic name (from the bookmark) and the value back to
* S_208FMF for processing.

Begin_Loop from(1) to(#A_Limit) Using(#A_Index)
Change #MarkIndex #A_Index

Set_Ref #BookMark #Document.BookMarks.Item<#MarkIndex>

If '#A_Index = 1'
If '#Document.ProtectionType *ne ''-1'''
Invoke #Document.unProtect
Endif
Endif

Set #BookMark.Range.Font Hidden(0)

* Invoke a local method to reformat the data and then signal it back to S_208FMF

Invoke #Com_Owner.SignalFound WithName(#BookMark.Name_COM) WithValue(#BookMark.Range.Text)

End_Loop

* Close the MS-Word document

Invoke #Application.Documents.Close SaveChanges(0)

Endif

* Finished, return control to S_208FMF

Endroutine

* -----------------------------------------
* Signal found information back to S_208FMF
* -----------------------------------------

Mthroutine SignalFound
Define_Map *input #s_208Name #WithName
Define_Map *input #s_208AVal #WithValue

Define #char256 *char 256
Define #Char10 *char 10 to_Overlay(#char256 1)
Define #Char246 *char 246 to_Overlay(#char256 11)

* Bookmarked information coming from form text fields often has the
* text " FORMTEXT " preceding the actual value of the field. All this
* routine does is look for this format and strip it off any field
* value before the information is passed back to S_208FMF by issuing
* an "InformationFound" signal

Change #Char256 #WithValue.Value

Case #Char10

When '= '' FORMTEXT '''
Signal InformationFound WithName(#BookMark.Name_COM) WithValue(#char246)

Otherwise
Signal InformationFound WithName(#BookMark.Name_COM) WithValue(#char256)

EndCase

Endroutine

* ----------------------------------------------
* Handle a shutdown request coming from S_208FMF
* ----------------------------------------------

MthRoutine Shutdown

* If a MS-Word environment has been created close it down

If_ref #Application is_Not(*null)
Invoke #Application.Quit SaveChanges(0)
Endif

* And then destroy all references to any part of it

Set_Ref (#BookMark #Document #Application) *null

Endroutine


END_COM