ActiveX Examples in Zim

You can find the following examples on the Example Application, as a part of Zim Product

Splitter Example

Example Name : ActiveX Splitter Sample

Control Used : Microsoft Forms 2.0 TextBox

Zim Program Source Code

localprocedure setPointToPix(out lPointsToPixels)

   let lPointsToPixels = 1.33333

endprocedure

%--------------------------------------------------------------

localprocedure moveSplitter(in lPointsToPixels, out oException)

on error

  let oException = $concat('The following error has occurred: ',$trim($lasterrmessage))

  return

endon

   let vProperty = $objGetProperty(fSplitter.splitter, "left")

   let MouseOffset = $eventparameter(3) * lPointsToPixels % (points to pixels)

   % move splitter window

   let vproperty = $tochar(vproperty,4) + MouseOffset

   let vResult = $objSetProperty(fSplitter.splitter, "left", vProperty)

   % move right pane

   let vProperty = $objGetProperty(fSplitter.text2, "left")

   let vProperty = $tochar(vproperty,4) + MouseOffset

   let vResult = $objSetProperty(fSplitter.text2, "left", vProperty)

   let vProperty = $objGetProperty(fSplitter.text2, "width")

   let vProperty = $tochar(vproperty,4) - MouseOffset

   let vResult = $objSetProperty(fSplitter.text2, "width", vProperty)

   % move left pane

   let vProperty = $objGetProperty(fSplitter.text1, "width")

   let vproperty = $tochar(vproperty,4) + MouseOffset

   let vResult = $objSetProperty(fSplitter.text1, "width", vproperty)

   let MouseOffset = $eventparameter(3)

   let vProperty = $objGetProperty(fSplitter.splitter, "left")

endprocedure

%--------------------------------------------------------------

procedure pAXSplitter()     local (lPointsToPixels, oException)

on error

  let oException = $messagebox({oException where $trim(oException) > '', \

                   $concat('The following error has occured: ',$trim($lasterrmessage))}, \

                   1,1,1,'pAXTreeView')

  form close fSplitter

  window close wSampleWindow

  return

endon

   SetPointToPix(lPointsToPixels)

   window open wSampleWindow

   window set (label 'Samples - AxtiveX Splitter') wSampleWindow

   window set (modal) wSampleWindow

   window set accelerator Escape

   form open fSplitter

   let vResult = $objSetProperty (fSplitter.text1, "Multiline", 1) \

       vResult = $objSetProperty (fSplitter.text2, "Multiline", 1) \

       vResult = $objSetProperty(fSplitter.splitter, "MousePointer","9") \

       fSplitter.text1 = 'Pane1' \

       fSplitter.text2 = 'Pane2'

   form set (objectevent 'mouseup') fSplitter.splitter

   while

      form display input

      case

         when event.eventname = 'mouseup'

            let oException = ''

            movesplitter (lPointsToPixels, oException)

            if $trim(oException) > ''

              set exception error

            endif

         when event.eventname in('Closed', 'Escape') \

              or event.eventtag in('Close')

            break

      endcase

   endwhile

   form close fSplitter

   window close wSampleWindow

endprocedure

Excel Example

Example Name : ActiveX Excel Sample – Send Values to Excel

Control Used : Microsoft Excel

 

Zim Program Source Code

procedure pAXExcel() local (vl_cell1, vl_cell2, vl_cell3, vl_loop)
window open waxexcel at center for daxexcel
form open daxexcel

form display

win activate

form set focus faxexcel1.Cell[1]

while

form input

case

when event.eventname="Closed" or event.fieldtag="Cancel_button"

window close

return

when event.fieldtag="OK_button"

%start up excel

let vExcelApp = $ObjCreate('Excel.Application')

%initialize the workbooks

let vExcelWorkbooks = $ObjGetProperty (vExcelApp, 'WorkBooks')

let vExcelWorkbook = $objRunMethod (vExcelWorkBooks, 'Add')

%make Excel visible

let vResult = $objsetproperty(vExcelApp, 'Visible' ,1)

%give it some data

let vl_loop=0

while (let vl_loop=vl_loop+1) <= 9

let vl_cell1 = {"A" wh vl_loop in (1,4,7), "B" wh vl_loop in (2,5,8), "C"}

let vl_cell2 = {"1" wh vl_loop < 4, "2" wh vl_loop between 4 and 6, "3"}

let vl_cell3 = $concat($trim(vl_cell1), $trim(vl_cell2))

let vExcelRange = $objGetProperty(vExcelApp, 'Range', vl_cell3)

let vResult = $objSetProperty(vExcelRange, 'Value', faxexcel1.cell[vl_loop])

endwhile

endcase

%destroy the objects

let vResult=$null

let vExcelWorkBooks=$null

let vExcelWorkBook=$null

let vExcelRange=$null

%close Excel

let vResult=$objRunMethod (vExcelApp, 'Quit')

let vResult=$null

let vExcelApp=$null

endwhile

endprocedure

Treeview Example

Example Name : ActiveX TreeView Sample

Control Used : Microsoft TreeView Control, version 6.0

 

Zim Program Source Code

procedure pAXTreeView() local (oException)

   let vimagelist = $objcreate('MsComCtlLib.ImageListCtrl')

   let vlistimages = $objgetproperty(vImageList, 'ListImages')

   %need to populate with at least one picture for it to be assignable

  let vImage = $objrunmethod(vlistimages, \

                      'add','key=one','Picture=samples\\treeview\\treeview.ico')

   window open wSampleWindow

   window set (modal) wSampleWindow

   window set (label 'Samples - Tree View Control')

   window set accelerator Escape

   form open fTreeView

   let vResult = $ObjSetProperty(fTreeView.Tree, 'linestyle', 1)

   let vResult = $ObjSetProperty(fTreeView.Tree, 'ImageList', vImageList)

   let vNodes = $ObjGetProperty(fTreeView.Tree, "nodes")

   out $objsetproperty(fTreeview.tree,"font","name","verdana")

   out $objsetproperty(fTreeview.tree,"font","size",18)

   find all Custs issue Orders sorted by Custs.CC Orders.OrderNo ->myset

   compute all myset where $distinct (Custs.CC) is not $null evaluate \

      ( let vNode = $ObjRunMethod(vNodes, 'Add', \

                    $null, \                                              % placeholder for relative

                    $null, \                                              % placeholder for relationship

                    $squeeze('', 'c', $trim(Custs.CC)), \                 % unnamed argument for Key

                    $squeeze('', 'text=', $trim(Custs.Company)))) \       % named argument for Text

      ( let vImage = $objrunmethod (vlistimages, 'add', \

                     $squeeze('', 'key=p', $trim(Custs.CC)), \

                     $squeeze('', 'Picture=', Custs.Photo))) \

      ( let $transmitkey = $objsetproperty(vNode, 'image', $squeeze('', 'p', $trim(Custs.CC))))

   compute all myset evaluate \

      ( let vNode = $ObjRunMethod(vNodes, 'Add', \

                    $concat('c', $trim(Custs.CC)), \                     % example of unnamed parameter

          $concat('key= order', $trim(Orders.OrderNo)), \

          $concat('text=', $trim($mask(Orders.OrderDate, 'MM/DD/YY'))), \

          'relationship=4'))

   while

      form display input

      case

         when event.eventtag = 'PropertyPages'

            let vResult = $objRunMethod(fTreeView.Tree, 'ShowProperties')

         when event.eventname in('Closed', 'Escape') \

              or event.eventtag in('Close')

            break

      endcase

   endwhile

   form close fTreeView

   window close wSampleWindow

endprocedure

OLE Automation Example

Here’s a new example, which is using OLE Automation only (there’s no form with an OLE object on it).  This is an example of accessing data in another (ODBC) database:

 

% ADO (ActiveX Data Objects) Sample

PROCEDURE pAdoTest() Local(firstName)

  Let cn = $ObjCreate("ADODB.Connection")

  Let rs = $ObjCreate("ADODB.RecordSet")

  out 'Connecting to the database...'

  let v1=$objsetproperty(cn,"ConnectionString","DSN=AccessCustomers")

  let v1=$objsetproperty(cn,"CursorLocation",3)  % adUseClient

  let v1=$objrunmethod(cn,"Open")

  out 'Preparing RecordSet...'

  let v1=$objsetproperty(rs,"Source","Select * from Customers")

  let v1=$objsetproperty(rs,"ActiveConnection",cn)

  out 'Opening the recordset...'

  let v1=$objrunmethod(rs,"Open")

  

  out 'Returned records:'

  while $objgetproperty(rs, 'EOF') = 0

     Out $ttrim($objgetproperty(rs, 'Fields', 'FirstName'))

     Let vResult = $ObjRunMethod(rs, 'MoveNext')

  endwhile

  Let cn = $Null  

  Let rs = $Null

ENDPROCEDURE

Word Example

Example Name : ActiveX Word Sample

Control Used : Microsoft Word

 

Zim Program Source Code

procedure pAXWord()  

win open waxword at center for faxword

form open faxword

form display

win activate

while

  form input

  case

  when event.fieldtag = "Cancel_Button" or event.eventname="Closed"

  win close

  return

when event.fieldtag = "OK_Button" and faxword.text_word is not $null

%start up Word

let vWordApp  = $ObjCreate('Word.Application')

let vWordDocs = $ObjGetProperty (vWordApp, 'Documents')

let vWordDoc  = $objRunMethod (vWordDocs, 'Add')

%make Word visible

let vResult = $objsetproperty(vWordApp, 'Visible' ,1)

% Select Range

  let vWordRange = $objRunMethod(vWordDoc, 'Range', '0', '0')

  %give it some data

  let vresult = $objRunMethod (vWordRange, 'InsertAfter', faxword.text_word)

%destroy the object

let vresult   = $null

let vWordDocs = $null

let vWordDoc  = $null

  %close Word Application

  let vResult = $objRunMethod (vWordApp, 'Quit')

let vResult   = $null

let vWordApp  = $null

  otherwise

  form set focus faxword.text_word

  endcase

endwhile

endprocedure