Recent Posts

Pages: 1 [2] 3 4 ... 10
11
Problems & Solutions / Re: O2 SB Embed
« Last post by JRS on March 31, 2021, 11:53:05 PM »
This is an example of getting and setting ScriptBasic variables from O2.

testvars.sb
Code: Script BASIC
  1. a = 1      
  2. b = .2    
  3. c = "Three"
  4.  

Code: Text
  1. % filename "getsetvars.exe"                                            
  2. includepath "$/inc/"                                                
  3. include "RTL32.inc"                                                
  4. include "sbembed.inc"                                              
  5. #console                                                            
  6. uses console                                                        
  7.                                                                    
  8. sys pProgram                                                        
  9. sbData *arg                                                                                                                
  10. string cr = chr(13,10)
  11.  
  12. string src = `IMPORT "testvars.sb"` + cr                              
  13.                                                                    
  14. pProgram = scriba_new(@newmem, @freemem)                            
  15. scriba_LoadConfiguration(pProgram, "C:\Windows\SCRIBA.INI")        
  16. scriba_SetFileName(pProgram, "none")                                
  17. scriba_LoadProgramString(pProgram, src, len(src))                  
  18. scriba_Run(pProgram, "")                                            
  19.                                                                    
  20. sys v_a = scriba_LookupVariableByName(pProgram, "main::a")
  21. sys v_b = scriba_LookupVariableByName(pProgram, "main::b")
  22. sys v_c = scriba_LookupVariableByName(pProgram, "main::c")
  23.  
  24. ' Get defined variable values
  25.  
  26. scriba_GetVariable(pProgram, v_a, @@arg)
  27. print arg.lng + cr
  28. scriba_GetVariable(pProgram, v_b, @@arg)
  29. print arg.dbl + cr
  30. scriba_GetVariable(pProgram, v_c, @@arg)
  31. print arg.str + cr + cr
  32.  
  33. ' Set variable values
  34.  
  35. scriba_SetVariable(pProgram, v_a, SBT_LONG, 101, 0.0, "", 0)
  36. scriba_SetVariable(pProgram, v_b, SBT_DOUBLE, 0, 2.2, "", 0)
  37. scriba_SetVariable(pProgram, v_c, SBT_STRING, 0, 0.0, "Thirty Three", 12)
  38.  
  39. ' Get changed variable values
  40.  
  41. scriba_GetVariable(pProgram, v_a, @@arg)
  42. print arg.lng + cr
  43. scriba_GetVariable(pProgram, v_b, @@arg)
  44. print arg.dbl + cr
  45. scriba_GetVariable(pProgram, v_c, @@arg)
  46. print arg.str + cr
  47.  
  48. scriba_DestroySbArgs(pProgram, arg, 1)
  49. scriba_destroy(pProgram)
  50.  


C:\OxygenBasic\projectsC\ScriptBasic\EmbedSb>getsetvars
1
0.2
Three

101
2.2000000000000002
Thirty Three

C:\OxygenBasic\projectsC\ScriptBasic\EmbedSb>

12
Problems & Solutions / Re: O2 SB Embed
« Last post by JRS on March 31, 2021, 03:59:29 PM »
Charles,

I"ve asked this before but is there a way I can call back to the O2 executable that started a VB6 OCX form? I think calling back to SB is going to work but O2 is preferable.
13
Problems & Solutions / Re: O2 SB Embed
« Last post by JRS on March 31, 2021, 11:34:19 AM »
The Sage BOI get first customer example seems to work.

Code: OxygenBasic
  1. ' O2 Sage BOI Example                                                  
  2.                                                                    
  3. % filename "sageboi.exe"                                            
  4. includepath "$/inc/"                                                
  5. include "RTL32.inc"                                                
  6. include "sbembed.inc"                                              
  7. #console                                                            
  8. uses console                                                        
  9.                                                                    
  10. sys pProgram                                                        
  11. sbData *arg                                                        
  12. sbData *argr                                                        
  13. string cr = chr(13,10)                                              
  14. int sb_call = 1                                                    
  15. int sb_get  = 2                                                    
  16. int sb_let  = 4                                                    
  17. int sb_set  = 8                                                    
  18. string src = "IMPORT sbembed.sbi" + cr                              
  19.                                                                    
  20. pProgram = scriba_new(@newmem, @freemem)                            
  21. scriba_LoadConfiguration(pProgram, "C:\Windows\SCRIBA.INI")        
  22. scriba_SetFileName(pProgram, "none")                                
  23. scriba_LoadProgramString(pProgram, src, len(src))                  
  24. scriba_Run(pProgram, "")                                            
  25.                                                                    
  26. @argr = scriba_NewSbArgs(pProgram,"u")                              
  27. sys fn1 = scriba_LookupFunctionByName(pProgram, "main::sb_create")  
  28. sys fn2 = scriba_LookupFunctionByName(pProgram, "main::sb_cbn")    
  29. sys fn3 = scriba_LookupFunctionByName(pProgram, "main::sb_release")
  30.  
  31. @arg = scriba_NewSbArgs(pProgram, "s", "ProvideX.Script")
  32. scriba_CallArgEx(pProgram, fn1, argr, 1, arg)
  33. sys oscript = argr.lng
  34. @arg = scriba_NewSbArgs(pProgram, "i s i s", oscript, "Init", sb_call, "C:\Sage\Sage 100 Standard\MAS90\Home")
  35. scriba_CallArgEx(pProgram, fn2, argr, 4, arg)
  36. @arg = scriba_NewSbArgs(pProgram, "i s i s", oscript, "NewObject", sb_set, "SY_Session")
  37. scriba_CallArgEx(pProgram, fn2, argr, 4, arg)
  38. sys osession = argr.lng
  39. @arg = scriba_NewSbArgs(pProgram, "i s i s", osession, "nSetUser", sb_call, "js", "MY_PASSWORD")
  40. scriba_CallArgEx(pProgram, fn2, argr, 4, arg)
  41. @arg = scriba_NewSbArgs(pProgram, "i s i s", osession, "nsetcompany", sb_call, "ABC")
  42. scriba_CallArgEx(pProgram, fn2, argr, 4, arg)
  43. @arg = scriba_NewSbArgs(pProgram, "i s i s s", osession, "nSetDate", sb_call, "A/R", "20210331")
  44. scriba_CallArgEx(pProgram, fn2, argr, 5, arg)
  45. @arg = scriba_NewSbArgs(pProgram, "i s i s i", oscript, "NewObject", sb_set, "AR_Customer_svc", osession)
  46. scriba_CallArgEx(pProgram, fn2, argr, 5, arg)
  47. sys ocust = argr.lng
  48. @arg = scriba_NewSbArgs(pProgram, "i s i", ocust, "nMoveFirst", sb_call)
  49. scriba_CallArgEx(pProgram, fn2, argr, 3, arg)
  50. @arg = scriba_NewSbArgs(pProgram, "i s i", ocust, "sCustomerNo", sb_get)
  51. scriba_CallArgEx(pProgram, fn2, argr, 3, arg)
  52. string CustomerNo = argr.str
  53. @arg = scriba_NewSbArgs(pProgram, "i s i", ocust, "sCustomerName", sb_get)
  54. scriba_CallArgEx(pProgram, fn2, argr, 3, arg)
  55. string CustomerName = argr.str
  56. @arg = scriba_NewSbArgs(pProgram, "i s i", ocust, "sCity", sb_get)
  57. scriba_CallArgEx(pProgram, fn2, argr, 3, arg)
  58. string City = argr.str
  59. @arg = scriba_NewSbArgs(pProgram, "i s i", ocust, "sState", sb_get)
  60. scriba_CallArgEx(pProgram, fn2, argr, 3, arg)
  61. string State = argr.str
  62. @arg = scriba_NewSbArgs(pProgram, "i s i", ocust, "sTelephoneNo", sb_get)
  63. scriba_CallArgEx(pProgram, fn2, argr, 3, arg)
  64. string TelephoneNo = argr.str
  65. @arg = scriba_NewSbArgs(pProgram, "i s i", ocust, "DropObject", sb_call)
  66. scriba_CallArgEx(pProgram, fn2, argr, 3, arg)
  67. @arg = scriba_NewSbArgs(pProgram, "i s i", osession, "DropObject", sb_call)
  68. scriba_CallArgEx(pProgram, fn2, argr, 3, arg)
  69. @arg = scriba_NewSbArgs(pProgram, "i", oscript)
  70. scriba_CallArgEx(pProgram, fn3, argr, 1, arg)
  71.  
  72. print "Customer:  " + CustomerNo " - " + CustomerName + " - " + City + " - " + State + " - " + TelephoneNo + cr
  73.  
  74. scriba_DestroySbArgs(pProgram, arg, 5)
  75. scriba_DestroySbArgs(pProgram, argr, 1)
  76. scriba_destroy(pProgram)
  77.  


C:\OxygenBasic\projectsC\ScriptBasic\EmbedSb>sageboi
Customer:  ABF - American Business Futures - Milwaukee - WI - (414) 555-4787

C:\OxygenBasic\projectsC\ScriptBasic\EmbedSb>

14
Problems & Solutions / Re: O2 SB Embed
« Last post by JRS on March 31, 2021, 12:03:00 AM »
Charles,

Since O2 is calling an instance of SB, I should be able to use my existing code in VB6 to callback to SB functions. Within those function I should be able to do COM calls.

All theory at this point. I'll give it a try in the morning.
15
Problems & Solutions / Re: O2 SB Embed
« Last post by JRS on March 30, 2021, 06:54:48 PM »
I was able to get the O2 Excel example to work.

Code: OxygenBasic
  1. ' O2 Excel Example
  2.  
  3. % filename "o2excel.exe"
  4. includepath "$/inc/"
  5. include "RTL32.inc"
  6. include "sbembed.inc"
  7. #console
  8. uses console
  9.  
  10. sys pProgram
  11. sbData *arg
  12. sbData *argr
  13. string cr = chr(13,10)
  14. int i, j
  15. int sb_call = 1
  16. int sb_get  = 2
  17. int sb_let  = 4
  18. int sb_set  = 8
  19. string src = "IMPORT sbembed.sbi" + cr
  20.  
  21. pProgram = scriba_new(@newmem, @freemem)
  22. scriba_LoadConfiguration(pProgram, "C:\Windows\SCRIBA.INI")
  23. scriba_SetFileName(pProgram, "none")
  24. scriba_LoadProgramString(pProgram, src, len(src))
  25. scriba_Run(pProgram, "")
  26.  
  27. @argr = scriba_NewSbArgs(pProgram,"u")
  28. sys fn1 = scriba_LookupFunctionByName(pProgram, "main::sb_create")
  29. sys fn2 = scriba_LookupFunctionByName(pProgram, "main::sb_cbn")
  30. sys fn3 = scriba_LookupFunctionByName(pProgram, "main::sb_release")
  31.  
  32. @arg = scriba_NewSbArgs(pProgram, "s", "Excel.Application")
  33. scriba_CallArgEx(pProgram, fn1, argr, 1, arg)
  34. sys oexcel = argr.lng
  35. @arg = scriba_NewSbArgs(pProgram, "i s i", oexcel, "Workbooks", sb_get)
  36. scriba_CallArgEx(pProgram, fn2, argr, 3, arg)
  37. sys oworkbook = argr.lng
  38. @arg = scriba_NewSbArgs(pProgram, "i s i", oWorkBook, "Add", sb_call)
  39. scriba_CallArgEx(pProgram, fn2, argr, 3, arg)
  40. sys oExcelWorkbook = argr.lng
  41. @arg = scriba_NewSbArgs(pProgram, "i s i i", oExcelWorkbook, "Worksheets", sb_get, 1)
  42. scriba_CallArgEx(pProgram, fn2, argr, 4, arg)
  43. sys oExcelSheet = argr.lng
  44. sys ocell
  45. for i = 1 to 10
  46.   for j = 1 to 10
  47.     @arg = scriba_NewSbArgs(pProgram, "i s i i i", oExcelSheet, "Cells", sb_get, i, j)
  48.     scriba_CallArgEx(pProgram, fn2, argr, 5, arg)
  49.     ocell = argr.lng
  50.     @arg = scriba_NewSbArgs(pProgram, "i s i s",  oCell, "Value", sb_let, "test-" + str(i) + "-" + str(j))
  51.     scriba_CallArgEx(pProgram, fn2, argr, 4, arg)
  52.     @arg = scriba_NewSbArgs(pProgram, "i", oCell)
  53.     scriba_CallArgEx(pProgram, fn3, argr, 1, arg)
  54.   next j
  55. next i
  56. @arg = scriba_NewSbArgs(pProgram, "i s i s", oExcelWorkbook, "SaveAs", sb_call, "C:\OxygenBasic\projectsC\ScriptBasic\EmbedSb\O2_Excel.xls")
  57. scriba_CallArgEx(pProgram, fn2, argr, 4, arg)
  58. @arg = scriba_NewSbArgs(pProgram, "i s i", oExcelWorkbook, "Close", sb_call)
  59. scriba_CallArgEx(pProgram, fn2, argr, 3, arg)
  60. @arg = scriba_NewSbArgs(pProgram, "i s i", oexcel, "Quit", sb_call)
  61. scriba_CallArgEx(pProgram, fn2, argr, 3, arg)
  62.  
  63. print "Spreadsheet Created" + cr
  64.  
  65. @arg = scriba_NewSbArgs(pProgram, "i", oExcelSheet)
  66. scriba_CallArgEx(pProgram, fn3, argr, 1, arg)
  67. @arg = scriba_NewSbArgs(pProgram, "i", oExcelWorkbook)
  68. scriba_CallArgEx(pProgram, fn3, argr, 1, arg)
  69. @arg = scriba_NewSbArgs(pProgram, "i", oworkbook)
  70. scriba_CallArgEx(pProgram, fn3, argr, 1, arg)
  71. @arg = scriba_NewSbArgs(pProgram, "i", oexcel)
  72. scriba_CallArgEx(pProgram, fn3, argr, 1, arg)
  73.  
  74. scriba_DestroySbArgs(pProgram, arg, 5)
  75. scriba_DestroySbArgs(pProgram, argr, 1)
  76. scriba_destroy(pProgram)
  77.  

This is the current status of the sbembed.sbi ScriptBasic IMPORT file.

Code: Script BASIC
  1. ' sbembed.sbi - ScriptBasic Embedded Function Wrappers
  2.  
  3. DECLARE COMMAND ArrayToXML ALIAS "xmlserialize" LIB "t"
  4. DECLARE SUB CREATE ALIAS "CreateObject" LIB "com"
  5. DECLARE SUB CBN ALIAS "CallByName" LIB "com"
  6. DECLARE SUB RELEASE ALIAS "ReleaseObject" LIB "com"
  7.  
  8. GLOBAL CONST sb_call = 1
  9. GLOBAL CONST sb_get  = 2
  10. GLOBAL CONST sb_let  = 4
  11. GLOBAL CONST sb_set  = 8
  12.  
  13. ' REPLACE
  14. FUNCTION sb_replace(basestr, searchstr, replacestr, occurances, startpos)
  15.   sb_replace = REPLACE(basestr, searchstr, replacestr, occurances, startpos)
  16. END FUNCTION
  17.  
  18. ' LIKE
  19. FUNCTION sb_like(basestr, mask)
  20.   ok = basestr LIKE mask
  21.   sb_like = ok
  22. END FUNCTION
  23.  
  24. ' MATCH
  25. FUNCTION sb_match(segment)
  26.   sb_match = JOKER(segment)
  27. END FUNCTION
  28.  
  29. ' SPLITA
  30. FUNCTION sb_splita(basestr, splitby)
  31.   SPLITA basestr BY splitby TO splitarray
  32.   sb_splita = ArrayToXML(splitarray)
  33. END FUNCTION  
  34.  
  35. ' COM - CREATE
  36. FUNCTION sb_create(obj_name)
  37.   obj = CREATE(8, obj_name)
  38.   sb_create = obj
  39. END FUNCTION
  40.  
  41. ' COM - CBN (CallByName)
  42. FUNCTION sb_cbn(obj, funcname, callypye, arg1, arg2, arg3, arg4)
  43.   IF arg1 = undef THEN
  44.     sb_cbn = CBN(obj, funcname, callypye)
  45.     GOTO Done
  46.   ELSE IF arg2 = undef THEN
  47.     sb_cbn = CBN(obj, funcname, callypye, arg1)
  48.     GOTO Done
  49.   ELSE IF arg3 = undef THEN
  50.     sb_cbn = CBN(obj, funcname, callypye, arg1, arg2)
  51.     GOTO Done
  52.   ELSE IF arg4 = undef THEN
  53.     sb_cbn = CBN(obj, funcname, callypye, arg1, arg2, arg3)
  54.     GOTO Done
  55.   ELSE IF arg4 <> undef THEN
  56.     sb_cbn = CBN(obj, funcname, callypye, arg1, arg2, arg3, arg4)
  57.   END IF
  58.   Done:
  59. END FUNCTION
  60.  
  61. ' COM - RELEASE
  62. FUNCTION sb_release(obj)
  63.   ok = RELEASE(obj)
  64.   sb_release = ok
  65. END FUNCTION
  66.  

This was my ScriptBasic test program using the sbembed.sbi IMPORT before writing the O2 version.

Code: Script BASIC
  1. ' Test COM
  2.  
  3. IMPORT sbembed.sbi
  4.  
  5. oexcel = sb_create("Excel.Application")
  6. oworkbook = sb_cbn(oexcel, "Workbooks", sb_get)
  7. oExcelWorkbook = sb_cbn(oWorkBook, "Add", sb_call)
  8. oExcelSheet = sb_cbn(oExcelWorkbook, "Worksheets", sb_get, 1)
  9. FOR i=1 TO 10
  10.   FOR j=1 TO 10
  11.     oCell = sb_cbn(oExcelSheet, "Cells", sb_get, i, j)
  12.     sb_cbn(oCell, "Value", sb_let, "test-" & i & "-" & j)
  13.     sb_release(oCell)
  14.   NEXT
  15. NEXT
  16. sb_cbn(oExcelWorkbook, "SaveAs", sb_call, "C:\\ScriptBASIC\\examples\\O2_Excel.xls")
  17. sb_cbn(oExcelWorkbook, "Close", sb_call)
  18. sb_cbn(oexcel, "Quit", sb_call)
  19.  
  20. PRINT "Spreadsheet Created\n"
  21.  
  22. sb_release(oExcelSheet)
  23. sb_release(oExcelWorkbook)
  24. sb_release(oworkbook)
  25. sb_release(oexcel)
  26.  


C:\OxygenBasic\projectsC\ScriptBasic\EmbedSb>o2excel
Spreadsheet Created

C:\OxygenBasic\projectsC\ScriptBasic\EmbedSb>
16
Problems & Solutions / Re: O2 SB Embed
« Last post by JRS on March 30, 2021, 03:50:41 AM »
It looks like my O2 COM/OLE automation insurance may pay off after all.  8)

Code: OxygenBasic
  1. ' Excel COM / OLE Example
  2.  
  3. % filename "o2excel.exe"
  4. includepath "$/inc/"
  5. include "RTL32.inc"
  6. include "sbembed.inc"
  7. #console
  8. uses console
  9.  
  10. sys pProgram, fnsn
  11. sbData *arg
  12. sbData *argr
  13. string cr = chr(13, 10)
  14. string src = "IMPORT sbembed.sbi" + cr
  15.  
  16. pProgram = scriba_new(@newmem, @freemem)
  17. scriba_LoadConfiguration(pProgram, "C:\Windows\SCRIBA.INI")
  18. scriba_SetFileName(pProgram, "none")
  19. scriba_LoadProgramString(pProgram, src, len(src))
  20. scriba_Run(pProgram, "")
  21.  
  22. @argr = scriba_NewSbArgs(pProgram,"u")
  23. fnsn = scriba_LookupFunctionByName(pProgram, "main::sb_create")
  24. @arg = scriba_NewSbArgs(pProgram, "s", "Excel.Application")
  25. scriba_CallArgEx(pProgram, fnsn, argr, 1, arg)
  26. print "Excel Object: " + str(argr.lng) + cr
  27.  
  28. scriba_DestroySbArgs(pProgram, arg, 1)
  29. scriba_DestroySbArgs(pProgram, argr, 1)
  30. scriba_destroy(pProgram)
  31.  


sbembed.sbi (added)
Code: Script BASIC
  1. DECLARE SUB CREATE ALIAS "CreateObject" LIB "com"
  2.  
  3. ' COM - CREATE
  4. FUNCTION sb_create(obj_name)
  5.   obj = CREATE(8, obj_name)
  6.   sb_create = obj
  7. END FUNCTION
  8.  


C:\OxygenBasic\projectsC\ScriptBasic\EmbedSb>o2excel
Excel Object: 7003868

C:\OxygenBasic\projectsC\ScriptBasic\EmbedSb>



It's late (into the wee morning) and I'll try to get the complete Excel example working when I wake up.

17
Problems & Solutions / Re: O2 SB Embed
« Last post by JRS on March 29, 2021, 11:05:59 PM »
I added SPLITA to the sbembed.sbi include. This also shows parsing a XML array returned string with LIKE / MATCH.

Notable Attributes
  • The splitby argument can be more than one character
  • The ScriptBasic program loaded was a string that consisted of a IMPORT of the sbembed.sbi include file. IMPORT only loads the code once even with multiple IMPORTs of the same module.

Code: Script BASIC
  1. ' SPLITA
  2. FUNCTION sb_splita(basestr, splitby)
  3.   SPLITA basestr BY splitby TO splitarray
  4.   sb_splita = ArrayToXML(splitarray)
  5. END FUNCTION  
  6.  

splita.o2bas
Code: OxygenBasic
  1. ' O2 - SB SPLITA Example
  2.  
  3. % filename "splita.exe"
  4. includepath "$/inc/"
  5. include "RTL32.inc"
  6. include "sbembed.inc"
  7. #console
  8. uses console
  9.  
  10. sys pProgram, fnsn
  11. sbData *arg
  12. sbData *argr
  13. string cr = chr(13, 10)
  14. string src = "IMPORT sbembed.sbi" + cr
  15. int i
  16.  
  17. pProgram = scriba_new(@newmem, @freemem)
  18. scriba_LoadConfiguration(pProgram, "C:\Windows\SCRIBA.INI")
  19. scriba_SetFileName(pProgram, "none")
  20. scriba_LoadProgramString(pProgram, src, len(src))
  21. scriba_Run(pProgram, "")
  22.  
  23. @argr = scriba_NewSbArgs(pProgram,"s", "")
  24. string datalist = "1,.2,Three"
  25. fnsn = scriba_LookupFunctionByName(pProgram, "main::sb_splita")
  26. @arg = scriba_NewSbArgs(pProgram, "s s", datalist, ",")
  27. scriba_CallArgEx(pProgram, fnsn, argr, 2, arg)
  28. print argr.str + cr + cr
  29. string xml = argr.str
  30. string mask = "*<S>*</S><S>*</S><S>*</S>*"
  31. @arg = scriba_NewSbArgs(pProgram, "s s", xml, mask)
  32. fnsn = scriba_LookupFunctionByName(pProgram, "main::sb_like")  
  33. @argr = scriba_NewSbArgs(pProgram,"i", 0)
  34. scriba_CallArgEx(pProgram, fnsn, argr, 2, arg)
  35. fnsn = scriba_LookupFunctionByName(pProgram, "main::sb_match")
  36. @argr = scriba_NewSbArgs(pProgram,"s", "")
  37. for i = 2 to 4
  38.   @arg = scriba_NewSbArgs(pProgram, "i", i)
  39.   scriba_CallArgEx(pProgram, fnsn, argr, 1, arg)
  40.   print argr.str + cr
  41. next i
  42.  
  43. scriba_DestroySbArgs(pProgram, arg, 2)
  44. scriba_DestroySbArgs(pProgram, argr, 1)
  45. scriba_destroy(pProgram)
  46.  

Code: XML
  1. <V><A LB="0" UB="2"><S>1</S><S>.2</S><S>Three</S></A></V>

1
.2
Three

18
Problems & Solutions / Re: O2 SB Embed
« Last post by JRS on March 29, 2021, 09:20:00 PM »
I got LIKE and MATCH working. This example shows using LIKE to parse the JSON response and using MATCH to extract the temperature. This example uses the new sb_embed.sbi include which is a library of ScriptBasic function wrappers.

weather.o2bas
Code: OxygenBasic
  1. ' O2 SB cURL OpenWeather Example
  2.  
  3. % filename "weather.exe"
  4. includepath "$/inc/"
  5. include "RTL32.inc"
  6. include "sbembed.inc"
  7. #console
  8. uses console
  9.  
  10. sys pProgram, fnsn
  11. sbData *arg
  12. sbData *argr
  13. string cr = chr(13,10)
  14.  
  15. pProgram = scriba_new(@newmem, @freemem)
  16. scriba_LoadConfiguration(pProgram, "C:\Windows\SCRIBA.INI")
  17. scriba_SetFileName(pProgram, "weather.sb")
  18. scriba_LoadSourceProgram(pProgram)
  19. scriba_Run(pProgram, "")
  20.  
  21. @arg = scriba_NewSbArgs(pProgram, "s", "Anacortes,US")
  22. fnsn = scriba_LookupFunctionByName(pProgram, "main::get_weather")  
  23. @argr = scriba_NewSbArgs(pProgram,"s", "")
  24. scriba_CallArgEx(pProgram, fnsn, argr, 1, arg)
  25. string json = argr.str
  26. string mask = `*temp":*,*`
  27. @arg = scriba_NewSbArgs(pProgram, "s s", json, mask)
  28. fnsn = scriba_LookupFunctionByName(pProgram, "main::sb_like")  
  29. @argr = scriba_NewSbArgs(pProgram,"i", 0)
  30. scriba_CallArgEx(pProgram, fnsn, argr, 2, arg)
  31. @arg = scriba_NewSbArgs(pProgram, "i", 2)
  32. fnsn = scriba_LookupFunctionByName(pProgram, "main::sb_match")
  33. @argr = scriba_NewSbArgs(pProgram,"s", "")
  34. scriba_CallArgEx(pProgram, fnsn, argr, 1, arg)
  35. print "Anacortes Temperature is " + argr.str + " F" + cr
  36.  
  37. scriba_DestroySbArgs(pProgram, arg, 2)
  38. scriba_DestroySbArgs(pProgram, argr, 1)
  39. scriba_destroy(pProgram)
  40.  

weather.sb
Code: Script BASIC
  1. ' OpenWeather - Curl Example
  2.  
  3. IMPORT sbembed.sbi
  4. IMPORT curl.sbi
  5.  
  6. FUNCTION Get_Weather(place)
  7.   ch = curl::init()
  8.   curl::option(ch, "URL", "http://api.openweathermap.org/data/2.5/weather?q=" & place & "&units=imperial&appid=MY_API_KEY")
  9.   curl::option(ch, "CUSTOMREQUEST", "GET")
  10.   response = curl::perform(ch)
  11.   curl::finish(ch)
  12.   Get_Weather = response
  13. END FUNCTION
  14.  

sbembed.sbi
Code: Script BASIC
  1. ' sbembed.sbi - ScriptBasic Embedded Function Wrappers
  2.  
  3. ' REPLACE
  4. FUNCTION sb_replace(basestr, searchstr, replacestr, occurances, startpos)
  5.   sb_replace = REPLACE(basestr, searchstr, replacestr, occurances, startpos)
  6. END FUNCTION
  7.  
  8. ' LIKE
  9. FUNCTION sb_like(basestr, mask)
  10.   ok = basestr LIKE mask
  11.   sb_like = ok
  12. END FUNCTION
  13.  
  14. ' MATCH
  15. FUNCTION sb_match(segment)
  16.   sb_match = JOKER(segment)
  17. END FUNCTION  
  18.  


C:\OxygenBasic\projectsC\ScriptBasic\EmbedSb>weather
Anacortes Temperature is 39.27 F

C:\OxygenBasic\projectsC\ScriptBasic\EmbedSb>



19
Problems & Solutions / Re: O2 SB Embed
« Last post by JRS on March 29, 2021, 05:20:38 PM »
I've cleaned up the Array2XML extension module function so it's easier to parse.

Code: XML
  1. <V><A LB="0" UB="5"><S>One</S><I>1</I><S>Two</S><R>0.200000</R><S>3</S><S>Three</S></A></V>

I'm working on adding SPLITA and LIKE callable functions from O2. The LIKE could be used to parse the XML array definition being returned,

Code: OxygenBasic
  1. ' O2 SB Array Passing
  2.  
  3. % filename "a2s.exe"
  4. includepath "$/inc/"
  5. include "RTL32.inc"
  6. include "sbembed.inc"
  7. #console
  8. uses console
  9.  
  10. sys pProgram. fnsn
  11. sbData *arg
  12. sbData *argr
  13.  
  14. pProgram = scriba_new(@newmem, @freemem)
  15. scriba_LoadConfiguration(pProgram, "C:\Windows\SCRIBA.INI")
  16. scriba_SetFileName(pProgram, "test.sb")
  17. scriba_LoadSourceProgram(pProgram)
  18. scriba_Run(pProgram, "")
  19.  
  20. @arg = scriba_NewSbArgs(pProgram, "u")
  21. fnsn = scriba_LookupFunctionByName(pProgram, "main::a2s")  
  22. @argr = scriba_NewSbArgs(pProgram,"s", "")
  23. scriba_CallArgEx(pProgram, fnsn, argr, 0, arg)
  24. print argr.str
  25.  
  26. scriba_DestroySbArgs(pProgram, argr, 1)
  27. scriba_destroy(pProgram)
  28.  

Code: Script BASIC
  1. DECLARE COMMAND ArrayToXML ALIAS "xmlserialize" LIB "t"
  2.  
  3. FUNCTION a2s
  4.   a{"One"} = 1
  5.   a{"Two"} = .2
  6.   a{"3"} = "Three"
  7.   a2s = ArrayToXML(a)
  8. END FUNCTION  
  9.  
20
Problems & Solutions / Re: O2 SB Embed
« Last post by JRS on March 28, 2021, 11:17:25 PM »
This is the REPLACE example but the ScriptBasic function wrapper is embedded in the O2 program. You can also load the binary format of your program (ready to run) which also protects your ScriptBasic code from viewing.

Code: OxygenBasic
  1. ' O2 - SB Source Embedding
  2.  
  3. % filename "repsrc.exe"
  4. includepath "$/inc/"
  5. include "RTL32.inc"
  6. include "sbembed.inc"
  7. #console
  8. uses console
  9.  
  10. sys pProgram, fnsn
  11. sbData *arg
  12. sbData *argr
  13. string cr = chr(13, 10)
  14. string src = "FUNCTION sb_replace(basestr, searchstr, replacestr, occurances, startpos)" + cr + _
  15.              "sb_replace = REPLACE(basestr, searchstr, replacestr, occurances, startpos)" + cr + _
  16.              "END FUNCTION" + cr
  17.  
  18. pProgram = scriba_new(@newmem, @freemem)
  19. scriba_LoadConfiguration(pProgram, "C:\Windows\SCRIBA.INI")
  20. scriba_SetFileName(pProgram, "none")
  21. scriba_LoadProgramString(pProgram, src, len(src))
  22. scriba_Run(pProgram, "")
  23.  
  24. @arg = scriba_NewSbArgs(pProgram, "s s s i i", "Hello World", "Hello", "Goodbye", 1, 1)
  25. fnsn = scriba_LookupFunctionByName(pProgram, "main::sb_replace")  
  26. @argr = scriba_NewSbArgs(pProgram,"s", "")
  27. scriba_CallArgEx(pProgram, fnsn, argr, 5, arg)
  28. print argr.str + cr
  29.  
  30. scriba_DestroySbArgs(pProgram, arg, 5)
  31. scriba_DestroySbArgs(pProgram, argr, 1)
  32. scriba_destroy(pProgram)
  33.  


C:\OxygenBasic\projectsC\ScriptBasic\EmbedSb>repsrc
Goodbye World

C:\OxygenBasic\projectsC\ScriptBasic\EmbedSb>
Pages: 1 [2] 3 4 ... 10