Simple COM program

 We shall consider a variant of the program written on VBA (Excel Macro)

List of COM Methods

The program should do the following:

1 Connect to Briz
2 Start program test.vb on server side
3 Get system information by system(100) and place it to the sheet
4 Execute TCL command "WHO" and place result to the sheet
5 Execute TCL command "create-file TSTPRG 1 7"
6 Generate and save PickBasic procedure TstExcelPrg
7 Execute TCL command compile-catalog TSTPRG TstExcelPrg
8 Read file "PIBS"
9 Execute TstExcelPrg in TSTPRG
10 Execute server GUI subroutine for copying

About style of the program. For brevity all checks are removed from the program.

The Text of the program:

 

Dim gpt As GP_Term.Document

Dim gpc As GP_Term.Connector

Declare objects
Sub TestOLE()
  Set gpc = New GP_Term.Connector Create connector to main object
  Set gpt = gpc.GetTerminal("GP_Term") Get GP_Term.Document named "GP_Term" (See ROT)
  Set gpc = Nothing Destroy connector

    Cells.Select
    Selection.NumberFormat = "@"

Formatting

    gpt.SendLine "test.vb"
    gpt.SendChar 13

Send to server "test.vb\r"

    Dim retArr As Variant

    gpt.DoSystem retArr, 100 Do System(100) on server side

    gpt.StringToArray retArr(0), retArr, ";"

Convert result to array

    Dim nval As Long

    For nval = 0 To UBound(retArr, 1)

       Cells(1, nval + 1) = retArr(nval)

    Next nval

Place result to cells
    gpt.ExecTCL "who" Execute TCL  "WHO"

     While gpt.GetTCLResult(retArr, 0) < 0

      DoEvents

    Wend

Wait and get result

    For nval = 0 To UBound(retArr, 1)

       Cells(2, nval + 1) = retArr(nval)

    Next nval

Place result to cells

    gpt.ExecTCL "create-file TSTPRG 1 7"

Execute TCL 

    While gpt.GetTCLResult(retArr, 0) < 0

       DoEvents

  Wend

Wait and get result

   For nval = 0 To UBound(retArr, 1)
       Cells(3, nval + 1) = retArr(nval)
   Next nval

Place result to cells
   Dim tmps As String

    tmps = "SUB TST(nArr)^ret=''^for i=1 to narr^ret<i>=i^next i^nArr=ret^return"

Prepare PickBasic subroutine text

    gpt.StringToArray tmps, retArr, "^"

Convert string to array

    gpt.SaveList "TSTPRG", "TstExcelPrg", retArr

Save SUB in TSTPRG as TstExcelPrg

    gpt.ExecTCL "compile-catalog TSTPRG TstExcelPrg"

Execute TCL 

    While gpt.GetTCLResult(retArr, 0) < 0
      DoEvents
   Wend

Wait and get result

   For nval = 0 To UBound(retArr, 1)
      Cells(4, nval + 1) = retArr(nval)
   Next nval

Place result to cells

    Dim flPIBS As Long

    Dim keyPIBS As Variant

    flPIBS = gpt.SelectOpenPickFile("PIBS")

Open server file "PIBS"

    gpt.ReadKFromPICKEx flPIBS, -1, retArr, keyPIBS

Read all items from "PIBS"
    gpt.ClosePICKFile flPIBS Close server file "PIBS"

    gpt.ConvertToSubArray retArr, Chr(1)

Convert result to MV array

    Dim i As Long

     Dim j As Long

     Application.ScreenUpdating = False

     For i = 0 To UBound(retArr, 1)

        For j = 0 To UBound(retArr(i), 1)

            Cells(6 + i, 1) = keyPIBS(i)

            Cells(6 + i, j + 2) = retArr(i)(j)

        Next j

    Next i

    Application.ScreenUpdating = True

Place result to cells

    ReDim retArr(0) 

    retArr(0) = 25

    gpt.ExecSubEx "TstExcelPrg", retArr Execute TstExcelPrg in TSTPRG

    While gpt.GetSubResult(retArr) < 0

        DoEvents

    Wend

Wait and get result

    gpt.ConvertToSubArray retArr, Chr(1)

Convert result to MV array

    For nval = 0 To UBound(retArr(0), 1)

        Cells(5, nval + 1) = retArr(0)(nval)

    Next nval 

Place result to cells

    ReDim retArr(4)

    retArr(0) = 0

    retArr(1) = ""

    retArr(2) = ""

    retArr(3) = ""

    retArr(4) = ""

    Application.WindowState = xlMinimized

    gpt.ExecSubEx "GPTOOL.CopyToFile", retArr

Execute GUI subroutine (cool)

    While gpt.GetSubResult(retArr) < 0

         DoEvents

     Wend

Wait and get result

    Application.WindowState = xlMaximized

    Cells.Select

    Selection.NumberFormat = "@"

Restore Excel

    gpt.EndMessageMap

Cancel Message Loop on Server

    Set gpt = Nothing

Destroy GP_Term.Document

End Sub

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

   

 

 

   

 

   

   

 

 

 

 

 

 

 

 

 

 

 

    

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

   

 

 

   

 

 

 

 

 

 

 

 

 

All questions:

infotools@hotmail.ru
mytmppost@mail.ru

 

 

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
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81