Recent Posts

Pages: 1 ... 5 6 [7] 8 9 10
61
Problems & Solutions / Re: COM OLE
« Last post by JRS on March 23, 2021, 10:49:26 AM »
The new Excel example doesn't print anything.  :(
62
Problems & Solutions / Re: COM OLE
« Last post by Charles Pegge on March 23, 2021, 10:47:38 AM »
You will need to remove the METHOD argument from objectByName.
63
Problems & Solutions / Re: COM OLE
« Last post by JRS on March 23, 2021, 10:44:57 AM »
I gave the Sage example a try with your new COMutil.inc

Code: OxygenBasic
  1. ' O2 Sage BOI
  2.  
  3. $filename "t.exe"                                    
  4. uses  COM/COMutil                                    
  5.  
  6.  
  7. CoInitialize null
  8.  
  9. CreateInterfaceByName "ProvideX.Script" oscript
  10. CallByName(oscript, "Init", BSTR {"C:\Sage\Sage 100 Standard\MAS90\Home"})
  11.  
  12. ObjectByName(oscript, "NewObject", METHOD, BSTR {"SY_Session"},osession)
  13. CallByName(osession, "nSetUser", BSTR {"js", "northstar"})
  14. CallByName(osession, "nsetcompany", BSTR {"ABC"})
  15. CallByName(osession, "nSetDate", BSTR {"A/R", "20210322"})
  16. CallByName(osession, "nSetModule", BSTR {"A/R"})
  17. ObjectByName(oscript, "NewObject", METHOD, BSTR {"AR_Customer_svc"}, osession, ocust)
  18. CmdByName(ocust, "nMoveFirst")
  19. GetByName(ocust, "sCustomerNo", customerno)
  20. GetByName(ocust, "sCustomerName", customername)
  21. GetByName(ocust, "sCity", city)
  22. GetByName(ocust, "sState", state)
  23. GetByName(ocust, "sTelephoneNo", telephoneno)
  24. CmdByName(ocust, "DropObject")
  25. CmdByName(osession, "DropObject")
  26.  
  27. ' print @osession 'check pointer
  28.  
  29. print "Customer:  ", customerno, "  ", customername, "  ", city, "  ", state, "  ", telephoneno
  30.  
  31. oscript.Release                                      
  32. CoUninitialize
  33.  

64
Problems & Solutions / Re: COM OLE
« Last post by Charles Pegge on March 23, 2021, 10:40:03 AM »
Some diagnostics to check valid Idispatch pointers

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)
print @oWorkBook
ObjectByName(oWorkBook, "Add", BSTR {0}, oExcelWorkbook)
print @oExcelWorkbook
ObjectByName(oExcelWorkbook, "Worksheets", BSTR {1}, oExcelSheet)
print @oExcelSheet
ObjectByName(oExcelSheet, "Range", BSTR {"G3"}, oRange)
print @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."
65
Problems & Solutions / Re: COM OLE
« Last post by JRS on March 23, 2021, 10:23:43 AM »
I updated the COMutil.inc and tried your program. No errors or spreadsheet created. Never gets to Spreadsheet Created. messagebox.
66
Problems & Solutions / Re: COM OLE
« Last post by Charles Pegge 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."


67
Problems & Solutions / Re: COM OLE
« Last post by JRS 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.  
68
Problems & Solutions / Re: COM OLE
« Last post by JRS 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.  

69
Problems & Solutions / Re: COM OLE
« Last post by JRS 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.  

70
Problems & Solutions / Re: COM OLE
« Last post by JRS 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?

Pages: 1 ... 5 6 [7] 8 9 10