Author Topic: COM OLE  (Read 3671 times)

0 Members and 1 Guest are viewing this topic.

JRS

  • Guest
Re: COM OLE
« Reply #15 on: March 18, 2021, 07:09:06 PM »
I gave this a try but the CallByName never returns an osession value. I do get past the first CallByName call.

Code: OxygenBasic
  1. ' O2 Sage BOI
  2.  
  3. $filename "t.exe"                                    
  4. uses  COM/COMutil                                    
  5. CoInitialize null
  6.  
  7. sys osession                                    
  8. CreateInterfaceByName "ProvideX.Script" oscript
  9. CallByName(oscript, "Init", "C:\Sage\Sage 100 Standard\MAS90\Home")
  10. osession = CallByName(oscript, "NewObject", "SY_Session")
  11. print osession
  12.  
  13. oscript.Release                                        
  14. CoUninitialize
  15.  
« Last Edit: March 18, 2021, 07:32:08 PM by John »

JRS

  • Guest
Re: COM OLE
« Reply #16 on: March 20, 2021, 09:42:13 AM »
Charles,

It looks the O2 COM/OLE API only supports passing strings. Longs / integers or iDispatch pointers aren't there yet. Are my assumptions correct?

Charles Pegge

  • Guest
Re: COM OLE
« Reply #17 on: March 21, 2021, 03:47:07 AM »
Hi John,

I think this will deliver objects:

Code: [Select]
'09:33 21/03/2021
' O2 Sage BOI
 
$filename "t.exe"                                   
uses  COM/COMutil

function CallByNameSV(IDispatch *vi, word flag, BSTR name, BSTR *sa=null, int c=0, VARIANT *vr=null) as int
===========================================================================================================
  int i
  VARIANT va[8] 'up to 8 params
  indexbase 1
  '
  for i=1 to c
   va[i].vt=VT_BSTR
   ?va[i].bstrVal=?sa[i] 'direct coupling
  next
  '
  err=CallByNameV(vi, flag, name, va, c, vr) 'VARIANT morph
  '
  for i=1 to c
    frees sa[i]
  next
  return err
end function

macro ObjectByName(vi,fl,nf,sa,sr,   rv)
========================================
  idispatch *sr
  VARIANT rv
  CallByNameSV(vi, fl, nf, sa, countof, rv)
  @sr=@rv.ppdispVal
end macro


CoInitialize null
 
CreateInterfaceByName "ProvideX.Script" oscript
CallByName(oscript, "Init", BSTR {"C:\Sage\Sage 100 Standard\MAS90\Home"})

'SB>>
'osession = COM::CBN(oscript, "NewObject", :SET, "SY_Session")

'longhand:
'idispatch *osession
'VARIANT rv
'CallByNameSV(oscript, SET, "NewObject", BSTR {"SY_Session"}, countof, rv)
'@osession=@rv.ppdispVal

ObjectByName(oscript, SET, "NewObject", BSTR {"SY_Session"},osession)

print @osession 'check pointer
 
oscript.Release                                       
CoUninitialize

JRS

  • Guest
Re: COM OLE
« Reply #18 on: March 21, 2021, 08:49:24 AM »
Thanks Charles!

I'll give this a try. How would I pass int/long arguments?

JRS

  • Guest
Re: COM OLE
« Reply #19 on: March 21, 2021, 09:31:50 AM »
Here is my attempt to get an object pointer.

Adding int SET = 8 causes the print of osession to be zero. (no errors)


Code: OxygenBasic
  1. ' O2 Sage BOI
  2.  
  3. $filename "t.exe"                                    
  4. uses  COM/COMutil                                    
  5.  
  6. function CallByNameSV(IDispatch *vi, word flag, BSTR name, BSTR *sa=null, int c=0, VARIANT *vr=null) as int
  7. ===========================================================================================================
  8.   int i
  9.   VARIANT va[8] 'up to 8 params
  10.  indexbase 1
  11.   '
  12.  for i=1 to c
  13.    va[i].vt=VT_BSTR
  14.    ?va[i].bstrVal=?sa[i] 'direct coupling
  15.  next
  16.   '
  17.  err=CallByNameV(vi, flag, name, va, c, vr) 'VARIANT morph
  18.  '
  19.  for i=1 to c
  20.     frees sa[i]
  21.   next
  22.   return err
  23. end function
  24.  
  25. macro ObjectByName(vi,fl,nf,sa,sr,   rv)
  26. ========================================
  27.   idispatch *sr
  28.   VARIANT rv
  29.   CallByNameSV(vi, fl, nf, sa, countof, rv)
  30.   @sr=@rv.ppdispVal
  31. end macro
  32.  
  33.  
  34. CoInitialize null
  35.  
  36. CreateInterfaceByName "ProvideX.Script" oscript
  37. CallByName(oscript, "Init", BSTR {"C:\Sage\Sage 100 Standard\MAS90\Home"})
  38.  
  39. ObjectByName(oscript, SET, "NewObject", BSTR {"SY_Session"},osession)
  40.  
  41. print @osession 'check pointer
  42.  
  43. oscript.Release                                      
  44. CoUninitialize
  45.  


Here is my Excel SB example so you can try these COM/OLE requirements on your box.

« Last Edit: March 21, 2021, 10:38:22 AM by John »

JRS

  • Guest
Re: COM OLE
« Reply #20 on: March 21, 2021, 03:39:56 PM »
Here is the firstcust.sb example using the SB COM debug DLL. Maybe this will be of help. It would be nice if I could define iDispatch arguments pointers as follows.

DISP {osession}

All returns to O2 should be either standard strings, longs or floats.

Code: Script BASIC
  1. ' Sage BOI (Business Object Interface)- first customer - selected columns
  2.  
  3. IMPORT COM.sbi
  4.  
  5. oscript = COM::CREATE(:SET, "ProvideX.Script")
  6. COM::CBN oScript, "Init", :CALL, "C:\\Sage\\Sage 100 Standard\\MAS90\\Home"
  7. osession = COM::CBN(oscript, "NewObject", :SET, "SY_Session")
  8. COM::CBN osession, "nSetUser", :CALL, "js", "northstar"
  9. COM::CBN osession, "nsetcompany", :CALL, "ABC"
  10. COM::CBN osession, "nSetDate", :CALL, "A/R", "20171218"
  11. COM::CBN osession, "nSetModule", :CALL, "A/R"
  12. ocust = COM::CBN(oscript, "NewObject", :SET, "AR_Customer_svc", osession)
  13. COM::CBN ocust, "nMoveFirst"
  14. CustomerNo$ = COM::CBN(ocust, "sCustomerNo", :GET)
  15. CustomerName$ = COM::CBN(ocust, "sCustomerName", :GET)
  16. City$ = COM::CBN(ocust, "sCity", :GET)
  17. State$ = COM::CBN(ocust, "sState", :GET)
  18. TelephoneNo$ = COM::CBN(ocust, "sTelephoneNo", :GET)
  19. COM::CBN ocust, "DropObject"
  20. COM::CBN osession, "DropObject"
  21. COM::RELEASE oscript
  22.  
  23. PRINT "Customer:  ", CustomerNo$, "  ", CustomerName$, "  ", City$, "  ", State$, "  ", TelephoneNo$, "\n"
  24.  


Code: Text
  1. C:\ScriptBASIC\sage>sbc firstcust.sb
  2.  
  3. CreateObject 2 args
  4. CreateObject(:SET, ProvideX.Script)
  5. ProvideX.Script seems to return d!↓w☺valid IDISPATCH pointer
  6.  
  7. CallByName 4 args
  8. CallByName(obj=a00fcc, method='Init', calltype=1 , comArgs=1)
  9. VTYPE_STRING: C:\Sage\Sage 100 Standard\MAS90\Home (iter=0)
  10. VT_EMPTY returned : return value from COM function was empty
  11.  
  12. CallByName 4 args
  13. CallByName(obj=a00fcc, method='NewObject', calltype=8 , comArgs=1)
  14. VTYPE_STRING/IDISPATCH: SY_Session (iter=0)
  15. VT_DISPATCH returned : return value from COM function was integer: a00f84
  16.  
  17. CallByName 5 args
  18. CallByName(obj=a00f84, method='nSetUser', calltype=1 , comArgs=2)
  19. VTYPE_STRING: northstar (iter=0)
  20. VTYPE_STRING: js (iter=1)
  21. VT_I4 returned : return value from COM function was integer: 1
  22.  
  23. CallByName 4 args
  24. CallByName(obj=a00f84, method='nsetcompany', calltype=1 , comArgs=1)
  25. VTYPE_STRING: ABC (iter=0)
  26. VT_I4 returned : return value from COM function was integer: 1
  27.  
  28. CallByName 5 args
  29. CallByName(obj=a00f84, method='nSetDate', calltype=1 , comArgs=2)
  30. VTYPE_STRING: 20171218 (iter=0)
  31. VTYPE_STRING: A/R (iter=1)
  32. VT_I4 returned : return value from COM function was integer: 1
  33.  
  34. CallByName 4 args
  35. CallByName(obj=a00f84, method='nSetModule', calltype=1 , comArgs=1)
  36. VTYPE_STRING: A/R (iter=0)
  37. VT_I4 returned : return value from COM function was integer: 1
  38.  
  39. CallByName 5 args
  40. CallByName(obj=a00fcc, method='NewObject', calltype=8 , comArgs=2)
  41. FROM BYREF => VTYPE_LONG/IDISPATCH: a00f84 is valid pointer
  42. VTYPE_STRING: AR_Customer_svc (iter=1)
  43. VT_DISPATCH returned : return value from COM function was integer: a011c4
  44.  
  45. CallByName 2 args
  46. CallByName(obj=a011c4, method='nMoveFirst', calltype=1 , comArgs=0)
  47. VT_I4 returned : return value from COM function was integer: 1
  48.  
  49. CallByName 3 args
  50. CallByName(obj=a011c4, method='sCustomerNo', calltype=2 , comArgs=0)
  51. VT_BSTR returned : return value from COM function was string: ABF
  52.  
  53. CallByName 3 args
  54. CallByName(obj=a011c4, method='sCustomerName', calltype=2 , comArgs=0)
  55. VT_BSTR returned : return value from COM function was string: American Business Futures
  56.  
  57. CallByName 3 args
  58. CallByName(obj=a011c4, method='sCity', calltype=2 , comArgs=0)
  59. VT_BSTR returned : return value from COM function was string: Milwaukee
  60.  
  61. CallByName 3 args
  62. CallByName(obj=a011c4, method='sState', calltype=2 , comArgs=0)
  63. VT_BSTR returned : return value from COM function was string: WI
  64.  
  65. CallByName 3 args
  66. CallByName(obj=a011c4, method='sTelephoneNo', calltype=2 , comArgs=0)
  67. VT_BSTR returned : return value from COM function was string: (414) 555-4787
  68.  
  69. CallByName 2 args
  70. CallByName(obj=a011c4, method='DropObject', calltype=1 , comArgs=0)
  71. VT_EMPTY returned : return value from COM function was empty
  72.  
  73. CallByName 2 args
  74. CallByName(obj=a00f84, method='DropObject', calltype=1 , comArgs=0)
  75. VT_EMPTY returned : return value from COM function was empty
  76. Customer:  ABF  American Business Futures  Milwaukee  WI  (414) 555-4787
  77.  
  78. C:\ScriptBASIC\sage>
  79.  
« Last Edit: March 21, 2021, 04:38:04 PM by John »

Charles Pegge

  • Guest
Re: COM OLE
« Reply #21 on: March 21, 2021, 04:58:18 PM »
I need to know how SET is implemented in gory detail. Do you have the source code for your BOI module?

JRS

  • Guest
Re: COM OLE
« Reply #22 on: March 21, 2021, 06:21:50 PM »
Here is an Excel example before Mike (miss him a lot!) added the ability to pass iDispatch argument pointers to the SB COM interface.

Code: Script BASIC
  1. IMPORT COM.sbi
  2.  
  3. filename = "C:\\ScriptBASIC\\examples\\warehouse.xls"
  4.  
  5. IF FileExists(filename) THEN
  6.   PRINT "File already exists deleting: ", filename,"\n"
  7.   DELETE filename
  8. END IF
  9.  
  10. oExcelApp = COM::CREATE(:SET, "Excel.Application")
  11.  
  12. IF oExcelApp = 0 THEN
  13.   PRINT "Failed to create Excel Object do you have it installed?\n"
  14.   END
  15. END IF
  16.  
  17. ' VBS: Set ExcelWorkbook = ExcelApp.Workbooks.Add
  18. oWorkBook = COM::CBN(oExcelApp, "Workbooks", :GET)
  19.  
  20. IF oWorkBook = 0 THEN
  21.   PRINT "Failed to create Workbook\n"
  22.   END
  23. END IF
  24.  
  25. oExcelWorkbook = COM::CBN(oWorkBook, "Add")
  26.  
  27. ' VBS: Set ExcelSheet = ExcelWorkbook.Worksheets(1)
  28. oExcelSheet = COM::CBN(oExcelWorkbook, "Worksheets", :GET, 1)
  29.  
  30. IF oExcelSheet = 0 THEN
  31.   PRINT "Failed to get oExcelSheet\n"
  32.   END
  33. END IF
  34.  
  35. ' Adding cells...
  36.  
  37. oRange =  COM::CBN(oExcelSheet, "Range", :GET, "G3")
  38.  
  39. IF oRange = 0 THEN
  40.   PRINT "Failed to get oRange\n"
  41.   END
  42. END IF
  43.  
  44. COM::CBN(oRange, "Value", :LET, "123")
  45. COM::RELEASE(oRange)
  46.  
  47. oRange =  COM::CBN(oExcelSheet, "Range", :GET, "B1:B5")
  48.  
  49. IF oRange = 0 THEN
  50.   PRINT "Failed to get oRange\n"
  51.   END
  52. END IF
  53.  
  54. ' Place BOLD border around range
  55. CONST XlBorderWeight_xlMedium = -4138
  56. COM::CBN(oRange, "BorderAround", :CALL, 1, XlBorderWeight_xlMedium, 3)
  57.  
  58. oInterior = COM::CBN(oRange, "Interior", :GET)
  59.  
  60. IF oInterior = 0 THEN
  61.   PRINT "Failed to get oInterior\n"
  62.   END
  63. END IF  
  64.  
  65. COM::CBN(oInterior, "ColorIndex", :LET, "38")
  66. COM::CBN(oInterior, "Pattern", :LET, "xlSolid")
  67.  
  68. COM::RELEASE(oRange)
  69. COM::RELEASE(oInterior)
  70.  
  71. FOR i=1 TO 10
  72.   FOR j=1 TO 10
  73. '   VBS: ExcelSheet.Cells(i, j).Value = "test-" & i & "-" & j
  74.    oCell = COM::CBN(oExcelSheet, "Cells", :GET, i, j)
  75.     COM::CBN(oCell, "Value", :LET, "test-" & i & "-" & j)
  76.     COM::RELEASE(oCell)
  77.   NEXT
  78. NEXT
  79.  
  80. ' Saving spreadsheet
  81. COM::CBN(oExcelWorkbook, "SaveAs", :CALL, filename)
  82. COM::CBN(oExcelWorkbook, "Close")
  83. COM::CBN(oExcelApp, "Quit")
  84.  
  85. ' Releasing objects from memory
  86. COM::RELEASE(oExcelSheet)
  87. COM::RELEASE(oExcelWorkbook)
  88. COM::RELEASE(oWorkBook)
  89. COM::RELEASE(oExcelApp)
  90.  

COM.sbi
Code: Script BASIC
  1. GLOBAL CONST :CALL   = 1
  2. GLOBAL CONST :GET    = 2
  3. GLOBAL CONST :LET    = 4
  4. GLOBAL CONST :SET    = 8
  5.  
  6. MODULE COM
  7.  
  8. DECLARE SUB ::CREATE  ALIAS "CreateObject"      LIB "com"
  9. DECLARE SUB ::CBN     ALIAS "CallByName"        LIB "com"
  10. DECLARE SUB ::RELEASE ALIAS "ReleaseObject"     LIB "com"
  11. DECLARE SUB ::GHO     ALIAS "GetHostObject"     LIB "com"
  12. DECLARE SUB ::GHS     ALIAS "GetHostString"     LIB "com"
  13. DECLARE SUB ::TN      ALIAS "TypeName"          LIB "com"
  14. DECLARE SUB ::DI      ALIAS "DescribeInterface" LIB "com"
  15. DECLARE SUB ::CB      ALIAS "SBCallBack"        LIB "com"
  16.  
  17. END MODULE
  18.  

Attached is the ScriptBasic COM module C source. Mike made the the changes (:SET and passing iDispatch pointers) to the CallByName function.

« Last Edit: March 23, 2021, 08:36:08 PM by John »

Charles Pegge

  • Guest
Re: COM OLE
« Reply #23 on: March 22, 2021, 07:21:41 AM »
What happens when you use METHOD/CALL which equals 1 instead of SET which equals 8 ?

Essentially, this is what happens inside your COM module with Mike's modifications.

PS You can use integer,, float and string arguments

PS I dont have Excel.
« Last Edit: March 22, 2021, 08:35:16 AM by Charles Pegge »

JRS

  • Guest
Re: COM OLE
« Reply #24 on: March 22, 2021, 12:32:05 PM »
I'll give that a try.

Thanks for the reply!

JRS

  • Guest
Re: COM OLE
« Reply #25 on: March 22, 2021, 12:43:12 PM »
That worked.

Code: Text
  1. ObjectByName(oscript, METHOD, "NewObject", BSTR {"SY_Session"},osession)
  2.  

Let me see if I can get the rest of the script going.

Bummer on no Excel.

Can I add the additional ObjectByName code to COM\util if this works?

« Last Edit: March 22, 2021, 01:43:55 PM by John »

JRS

  • Guest
Re: COM OLE
« Reply #26 on: March 22, 2021, 05:56:35 PM »
Here is where I'm at.

Code: OxygenBasic
  1. ' O2 Sage BOI
  2.  
  3. $filename "t.exe"                                    
  4. uses  COM/COMutil                                    
  5.  
  6.  
  7. function CallByNameSV(IDispatch *vi, word flag, BSTR name, BSTR *sa=null, int c=0, VARIANT *vr=null) as int
  8. ===========================================================================================================
  9.   int i
  10.   VARIANT va[8] 'up to 8 params
  11.  indexbase 1
  12.   '
  13.  for i=1 to c
  14.    va[i].vt=VT_BSTR
  15.    ?va[i].bstrVal=?sa[i] 'direct coupling
  16.  next
  17.   '
  18.  err=CallByNameV(vi, flag, name, va, c, vr) 'VARIANT morph
  19.  '
  20.  for i=1 to c
  21.     frees sa[i]
  22.   next
  23.   return err
  24. end function
  25.  
  26. macro ObjectByName(vi,fl,nf,sa,sr,   rv)
  27. ========================================
  28.   idispatch *sr
  29.   VARIANT rv
  30.   CallByNameSV(vi, fl, nf, sa, countof, rv)
  31.   @sr=@rv.ppdispVal
  32. end macro
  33.  
  34.  
  35. CoInitialize null
  36.  
  37. CreateInterfaceByName "ProvideX.Script" oscript
  38. CallByName(oscript, "Init", BSTR {"C:\Sage\Sage 100 Standard\MAS90\Home"})
  39.  
  40. ObjectByName(oscript, METHOD, "NewObject", BSTR {"SY_Session"},osession)
  41. CallByName(osession, "nSetUser", BSTR {"js", "MY_PASSWORD"})
  42. CallByName(osession, "nsetcompany", BSTR {"ABC"})
  43. CallByName(osession, "nSetDate", BSTR {"A/R", "20210322"})
  44. CallByName(osession, "nSetModule", BSTR {"A/R"})
  45. ObjectByName(oscript, "NewObject", METHOD, BSTR {"AR_Customer_svc"}, osession, ocust)
  46. CmdByName(ocust, "nMoveFirst")
  47. GetByName(ocust, "sCustomerNo", customerno)
  48. GetByName(ocust, "sCustomerName", customername)
  49. GetByName(ocust, "sCity", city)
  50. GetByName(ocust, "sState", state)
  51. GetByName(ocust, "sTelephoneNo", telephoneno)
  52. CmdByName(ocust, "DropObject")
  53. CmdByName(osession, "DropObject")
  54.  
  55. ' print @osession 'check pointer
  56.  
  57. print "Customer:  ", customerno, "  ", customername, "  ", city, "  ", state, "  ", telephoneno
  58.  
  59. oscript.Release                                      
  60. CoUninitialize
  61.  


JRS

  • Guest
Re: COM OLE
« Reply #27 on: March 22, 2021, 08:28:21 PM »
Here my attempt at the Excel demo.

Code: OxygenBasic
  1. ' O2 Excel Example
  2.  
  3. $filename "exceldemo.exe"                                    
  4. uses  COM/COMutil                                    
  5.  
  6. string filename
  7. int i, j
  8.  
  9. filename = "C:\OxygenBasic\examples\COM\exceldemo.xls"
  10. CreateInterfaceByName "Excel.Application" oExcelApp
  11. GetByName(oExcelApp, "Workbooks", oWorkBook)
  12. CallByName(oWorkBook, "Add", oExcelWorkbook)
  13. GetByName(oExcelWorkbook, "Worksheets", 1, oExcelSheet)
  14. GetByName(oExcelSheet, "Range", BSTR {"G3"}, oRange)
  15. LetByName(oRange, "Value", BSTR {"123"})
  16. oRange.Release
  17. GetByName(oExcelSheet, "Range", BSTR {"B1:B5"}, oRange)
  18. CallByName(oRange, "BorderAround", 1, -4138, 3)
  19. GetByName(oRange, "Interior", oInterior)
  20. LetByName(oInterior, "ColorIndex", BSTR {"38"})
  21. LetByName(oInterior, "Pattern", BSTR {"xlSolid"})
  22. oRange.Release
  23. oInterior.Release
  24. for i = 0 to 10
  25.   for j = 0 to 10
  26.     GetByName(oExcelSheet, "Cells", i, j, oCell)
  27.     LetByName(oCell, "Value", BSTR {"test-" + i + "-" + j})
  28.     oCell.Release
  29.   next j  
  30. next i    
  31. CallByName(oExcelWorkbook, "SaveAs", BSTR {filename})
  32. CmdByName(oExcelWorkbook, "Close")
  33. CmdByName(oExcelApp, "Quit")
  34. oExcelSheet.Release
  35. oExcelWorkbook.Release
  36. oWorkBook.Release
  37. oExcelApp.Release
  38.  
  39. print "Speadsheet Created."
  40.  


JRS

  • Guest
Re: COM OLE
« Reply #28 on: March 22, 2021, 10:04:18 PM »
This attempt used ObjectByName() to return object pointers SB returned with CALL and GET.

Code: OxygenBasic
  1. ' O2 Excel Example
  2.  
  3. $filename "exceldemo.exe"                                    
  4. uses  COM/COMutil                                    
  5.  
  6. function CallByNameSV(IDispatch *vi, word flag, BSTR name, BSTR *sa=null, int c=0, VARIANT *vr=null) as int
  7. ===========================================================================================================
  8.   int i
  9.   VARIANT va[8] 'up to 8 params
  10.  indexbase 1
  11.   '
  12.  for i=1 to c
  13.    va[i].vt=VT_BSTR
  14.    ?va[i].bstrVal=?sa[i] 'direct coupling
  15.  next
  16.   '
  17.  err=CallByNameV(vi, flag, name, va, c, vr) 'VARIANT morph
  18.  '
  19.  for i=1 to c
  20.     frees sa[i]
  21.   next
  22.   return err
  23. end function
  24.  
  25. macro ObjectByName(vi,fl,nf,sa,sr,   rv)
  26. ========================================
  27.   idispatch *sr
  28.   VARIANT rv
  29.   CallByNameSV(vi, fl, nf, sa, countof, rv)
  30.   @sr=@rv.ppdispVal
  31. end macro
  32.  
  33.  
  34. string filename
  35. int i, j
  36.  
  37. filename = "C:\OxygenBasic\examples\COM\exceldemo.xls"
  38. CreateInterfaceByName "Excel.Application" oExcelApp
  39. ObjectByName(oExcelApp, METHOD, "Workbooks", oWorkBook)
  40. ObjectByName(oWorkBook, METHOD, "Add", oExcelWorkbook)
  41. ObjectByName(oExcelWorkbook, METHOD, "Worksheets", 1, oExcelSheet)
  42. ObjectByName(oExcelSheet, METHOD, "Range", BSTR {"G3"}, oRange)
  43. LetByName(oRange, "Value", BSTR {"123"})
  44. oRange.Release
  45. ObjectByName(oExcelSheet, METHOD, "Range", BSTR {"B1:B5"}, oRange)
  46. CallByName(oRange, "BorderAround", 1, -4138, 3)
  47. ObjectByName(oRange, METHOD, "Interior", oInterior)
  48. LetByName(oInterior, "ColorIndex", BSTR {"38"})
  49. LetByName(oInterior, "Pattern", BSTR {"xlSolid"})
  50. oRange.Release
  51. oInterior.Release
  52. for i = 0 to 10
  53.   for j = 0 to 10
  54.     ObjectByName(oExcelSheet, METHOD, "Cells", i, j, oCell)
  55.     LetByName(oCell, "Value", BSTR {"test-" + str(i) + "-" + str(j)})
  56.     oCell.Release
  57.   next j  
  58. next i    
  59. CallByName(oExcelWorkbook, "SaveAs", BSTR {filename})
  60. CmdByName(oExcelWorkbook, "Close")
  61. CmdByName(oExcelApp, "Quit")
  62. oExcelSheet.Release
  63. oExcelWorkbook.Release
  64. oWorkBook.Release
  65. oExcelApp.Release
  66.  
  67. print "Speadsheet Created."
  68.  
« Last Edit: March 22, 2021, 10:29:54 PM by John »

Charles Pegge

  • Guest
Re: COM OLE
« Reply #29 on: March 23, 2021, 10:08:35 AM »
Hi John,

Latest ComUtil with simplified ObjectByName

Code: [Select]
'07:01 23/03/2021
$filename "exceldemo.exe"
'uses RTL32                                   
uses  COM/COMutil                                   
 
 
string filename
int i, j
 
filename = "C:\OxygenBasic\examples\COM\exceldemo.xls"
CreateInterfaceByName "Excel.Application" oExcelApp
ObjectByName(oExcelApp, "Workbooks", BSTR {}, oWorkBook)
ObjectByName(oWorkBook, "Add", BSTR {0}, oExcelWorkbook)
ObjectByName(oExcelWorkbook, "Worksheets", BSTR {1}, oExcelSheet)
ObjectByName(oExcelSheet, "Range", BSTR {"G3"}, oRange)
LetByName(oRange, "Value", 123)
oRange.Release
ObjectByName(oExcelSheet, "Range", BSTR {"B1:B5"}, oRange)
CallByName(oRange, "BorderAround", BSTR {1, -4138, 3})
ObjectByName(oRange, "Interior", BSTR {1}, oInterior)
LetByName(oInterior, "ColorIndex", 38)
LetByName(oInterior, "Pattern", "xlSolid")
oRange.Release
oInterior.Release
for i = 0 to 10
  for j = 0 to 10
    ObjectByName(oExcelSheet, "Cells", BSTR {i, j}, oCell)
    LetByName(oCell, "Value", "test-" + str(i) + "-" + str(j))
    oCell.Release
  next j   
next i   
CallByName(oExcelWorkbook, "SaveAs", BSTR {filename})
CmdByName(oExcelWorkbook, "Close")
CmdByName(oExcelApp, "Quit")
oExcelSheet.Release
oExcelWorkbook.Release
oWorkBook.Release
oExcelApp.Release
 
print "Speadsheet Created."