Recent Posts

Pages: 1 [2] 3 4 ... 10
11
Scripting Languages / Re: ScriptBasic Core Windows 32 bit - ODBC
« Last post by John on May 25, 2021, 12:32:09 am »
This example uses the ODBC extension module to get the customers from the Sage 100 ABC demo company.

Code: Script BASIC
  1. ' Sage 100 Customers - ABC Demo (ProvideX ODBC Driver)
  2.  
  3. IMPORT odbc.sbi
  4.  
  5. dbh = odbc::RealConnect("SOTAMAS90","","")
  6. odbc::Query(dbh,"SELECT * FROM AR_Customer")
  7.  
  8. WHILE odbc::FetchHash(dbh, column)
  9.   PRINT column{"CustomerNo"}," - ",column{"CustomerName"}," - ",column{"TelephoneNo"},"\n"
  10. WEND
  11.  
  12. odbc::Close(dbh)
  13.  


C:\sb_build\examples>sbc odbc_100.sb
ABF - American Business Futures - (414) 555-4787
ABS - ABS - Sage cloud for invoices - (949) 555-7814
AVNET - Avnet Processing Corp - (414) 555-2635
BRESLIN - Breslin Parts Supply - (414) 555-9654
HILLSB - Hillsboro Service Center - (414) 555-6599
INACTIV - Inactive Customer **INACTIVE** - (414) 555--8747
INTMEX - Int. Cust with Mexican Address Name expanded to 50 - +52 646 177 1466
MAVRK - Maverick Papers - (312) 861-1200
RSSUPPL - R & S Supply Corp. - (414) 555-5587
SHEPARD - Shepard Motorworks - (414) 555-6544
ALLENAP - Allen's Appliance Repair - (714) 555-3121
AMERCON - American Concrete Service - (714) 555-2134
ATOZ - A To Z Carpet Supply - (714) 555-2231
AUTOCR - Autocraft Accessories - (714) 555-0101
BAYPYRO - Bay Pyrotronics Corp. - (415) 555-9654
CAPRI - Capri Sailing Ships - (714) 555-4421
CUSTOM - Custom Craft Products - (714) 555-7848
GREALAR - Greater Alarm Company - (714) 555-5531
JELLCO - Jellco Packing - (714) 555-9451
ORANGE - Orange Door & Window Co. - (714) 555-7823

C:\sb_build\examples>

12
Scripting Languages / Re: ScriptBasic Core Windows 32 bit - FFI
« Last post by John on May 25, 2021, 12:27:15 am »
This example uses the DYC extension module to make a dynamic FFI call to the Windows MessageBox API function.

Code: Script BASIC
  1. ' DYC - FFI Extension
  2.  
  3. DECLARE SUB DLL ALIAS "dyc" LIB "dyc"
  4.  
  5. PRINT DLL("ms,i,USER32.DLL,MessageBox,PZZL", 0, "Message Text", "Title", 3)
  6.  
  7. '""" Return Values
  8. Titlebar Exit = 2
  9. Yes = 6
  10. No = 7
  11. Cancel = 2
  12. """
  13.  


C:\sb_build\examples>sbc dyc_msgbox.sb
6
C:\sb_build\examples>

13
Scripting Languages / Re: ScriptBasic Core Windows 32 bit - cURL
« Last post by John on May 25, 2021, 12:21:13 am »
This example uses the cURL extension module to download the text version of the War and Peace book.

Code: Script BASIC
  1. 'cURL Example - Download War & Peace book as text file.
  2.  
  3. IMPORT curl.sbi
  4.  
  5. ch = curl::init()
  6. curl::option(ch, "URL", "http://www.textfiles.com/etext/FICTION/warpeace.txt")
  7. curl::option(ch, "FILE", "warpeace.txt")
  8. curl::perform(ch)
  9. PRINT curl::info(ch, "EFFECTIVE_URL"),"\n"
  10. PRINT FORMAT("Data downloaded: %0.0f bytes.\n", curl::info(ch, "SIZE_DOWNLOAD"))
  11. PRINT FORMAT("Total download time: %0.3f sec.\n", curl::info(ch, "TOTAL_TIME"))
  12. PRINT FORMAT("Average download speed: %0.3f kbyte/sec.\n", curl::info(ch, "SPEED_DOWNLOAD") / 1024)
  13. curl::finish(ch)
  14.  


C:\sb_build\examples>sbc curl_wget.sb
http://www.textfiles.com/etext/FICTION/warpeace.txt
Data downloaded: 4434670 bytes.
Total download time: 1.672 sec.
Average download speed: 2590.150 kbyte/sec.

C:\sb_build\examples>

14
Scripting Languages / Re: ScriptBasic Core Windows 32 bit - COM Excel
« Last post by John on May 25, 2021, 12:02:59 am »
This example populates an Excel spreadsheet using the COM/OLE Automation extension module.

Code: Script BASIC
  1. ' Excel Example
  2.  
  3. IMPORT com.sbi
  4.  
  5. oExcelApp = COM::CREATE(:SET, "Excel.Application")
  6. oWorkBook = COM::CBN(oExcelApp, "Workbooks", :GET)
  7. oExcelWorkbook = COM::CBN(oWorkBook, "Add", :CALL)
  8. oExcelSheet = COM::CBN(oExcelWorkbook, "Worksheets", :GET, 1)
  9. FOR i=1 TO 10
  10.   FOR j=1 TO 10
  11.     oCell = COM::CBN(oExcelSheet, "Cells", :GET, i, j)
  12.     COM::CBN(oCell, "Value", :LET, "test-" & i & "-" & j)
  13.     COM::RELEASE(oCell)
  14.   NEXT
  15. NEXT
  16. COM::CBN(oExcelWorkbook, "SaveAs", :CALL, CURDIR() & "\\sbexcel.xlsx")
  17. COM::CBN(oExcelWorkbook, "Close", :CALL)
  18. COM::CBN(oExcelApp, "Quit", :CALL)
  19.  
  20. PRINT "Spreadsheet Created\n"
  21.  
  22. COM::RELEASE(oExcelSheet)
  23. COM::RELEASE(oExcelWorkbook)
  24. COM::RELEASE(oWorkBook)
  25. COM::RELEASE(oExcelApp)
  26.  
15
Scripting Languages / Re: ScriptBasic Core Windows 32 bit - Sage 100 BOI
« Last post by John on May 24, 2021, 11:55:40 pm »
This is an example of using the COM/OLE extension module with the Sage 100 accounting software getting the first Customer in the table.

Code: Script BASIC
  1. ' Sage 100 - First Customer - Print 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.  
  8. osession = COM::CBN(oscript, "NewObject", :SET, "SY_Session")
  9. COM::CBN(osession, "nSetUser", :CALL, "UserID", "Password")
  10. COM::CBN(osession, "nsetcompany", :CALL, "ABC")
  11. COM::CBN(osession, "nSetDate", :CALL, "A/R", "20210520")
  12. COM::CBN(osession, "nSetModule", :CALL, "A/R")
  13. ocust = COM::CBN(oscript, "NewObject", :SET, "AR_Customer_svc", osession)
  14. COM::CBN(ocust, "nMoveFirst", :CALL)
  15. CustomerNo = COM::CBN(ocust, "sCustomerNo", :GET)
  16. CustomerName = COM::CBN(ocust, "sCustomerName", :GET)
  17. City = COM::CBN(ocust, "sCity", :GET)
  18. State = COM::CBN(ocust, "sState", :GET)
  19. TelephoneNo = COM::CBN(ocust, "sTelephoneNo", :GET)
  20. COM::CBN(ocust, "DropObject", :CALL)
  21. COM::CBN(osession, "DropObject", :CALL)
  22. COM::RELEASE(oscript)
  23.  
  24. PRINT "Customer:  ", CustomerNo, "  ", CustomerName, "  ", City, "  ", State, "  ", TelephoneNo, "\n"
  25.  


C:\sb_build\examples>sbc com_100.sb
Customer:  ABF  American Business Futures  Milwaukee  WI  (414) 555-4787

C:\sb_build\examples>

16
Scripting Languages / Re: ScriptBasic Core Windows 32 bit - CIO
« Last post by John on May 24, 2021, 11:31:11 pm »
The cio_colors.sb program uses the CIO extension module for console mode screen attributes.

Code: Script BASIC
  1. ' Display all the possible console character colors
  2.  
  3. IMPORT cio.sbi
  4.  
  5. cio::SetColor FWhite
  6. cio::cls
  7. cio::SetTitle "Testing console colors"
  8. FOR i = 1 TO 255
  9.   cio::gotoxy +(i \ 16) * 4 , +(i % 16) * 2
  10.   cio::gotoxy( (i \ 16) * 4 , +(i % 16) * 2 )
  11.   cio::gotoxy (i \ 16) * 4 , +(i % 16) * 2
  12.   cio::SetColor (i)
  13.   j = i
  14.   IF i < 100 THEN j = "0" & j
  15.   PRINT j
  16. NEXT i
  17. cio::SetColor FWhite
  18. cio::SetCursor 0
  19. i = cio::getch()
  20. cio::cls
  21.  
17
Scripting Languages / ScriptBasic Core Windows 32 bit Install
« Last post by John on May 24, 2021, 11:24:01 pm »
The attached ScriptBasic Windows install is a core distribution with the essential extension modules included. A User Guide is included as a Windows .CHM help file. The following posts to this thread are examples that are also included with the install program.



Core Extension Modules
  • COM/OLE Automation
  • cURL Library
  • ODBC
  • SQLite
  • Dynamic FFI
  • Asynchronous / Synchronous Threading

ScriptBasic User Guide

ScriptBasic SandBox Repository

ScriptBasic Download Attached
18
Scripting Languages / Re: CBASIC
« Last post by John on May 14, 2021, 10:12:38 pm »
I'm working on extending the CBASIC language syntax by including the ScriptBasic embedded interface and its language function wrappers.

I'll get a CBASIC project going in the sandbox to document and provide examples of its use.
19
Scripting Languages / Re: CBASIC
« Last post by John on May 13, 2021, 12:34:22 am »
A good example of CBASIC is the SDL_gfx extension module I wrote. CBASIC is a weaning language to help BASIC programmers learn C and still feel like home.

You can use as much of CBASIC syntax you wish with your C programs. CBASIC just substitutes C syntax with BASIC.

https://basic-sandbox.us/scriptbasic/extensions/-/blob/master/extensions/gfx/interface.c
20
Scripting Languages / CBASIC - Excel
« Last post by John on May 10, 2021, 10:10:09 pm »
This is the Excel example in CBASIC. This example uses the ScriptBasic COM/OLE automation extension module.

Code: C
  1. // gcc cbasic_excel.c -IC:\sbgcc\source libscriba.dll -lpthread -o cbasic_excel
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <getopt.h>
  7. #include "scriba.h"
  8. #include "cbasic.h"
  9.  
  10. MAIN
  11. BEGIN_FUNCTION
  12.   DIM pSbProgram AS pProgram;
  13.   DIM pSbData AS arg;
  14.   DIM pSbData AS argr;
  15.   DIM int AS sb_call = 1;
  16.   DIM int AS sb_get  = 2;
  17.   DIM int AS sb_let  = 4;
  18.   DIM int AS sb_set  = 8;
  19.   DIM int AS i, j;
  20.   DIM char AS src[] = "IMPORT sbembed.sbi\n";
  21.  
  22.   pProgram = scriba_new(malloc,free);
  23.   scriba_LoadConfiguration(pProgram, "C:\\Windows\\SCRIBA.INI");
  24.   scriba_SetFileName(pProgram, "none");
  25.   scriba_LoadProgramString(pProgram, src, strlen(src));
  26.   scriba_Run(pProgram, "");
  27.  
  28.   argr = scriba_NewSbArgs(pProgram,"u");
  29.   DIM int AS fn1 = scriba_LookupFunctionByName(pProgram, "main::sb_create");
  30.   DIM int AS fn2 = scriba_LookupFunctionByName(pProgram, "main::sb_cbn");
  31.   DIM int AS fn3 = scriba_LookupFunctionByName(pProgram, "main::sb_release");
  32.   arg = scriba_NewSbArgs(pProgram, "s", "Excel.Application");
  33.   scriba_CallArgEx(pProgram, fn1, argr, 1, arg);
  34.   DIM unsigned long AS oexcel = argr[0].v.l;
  35.   arg = scriba_NewSbArgs(pProgram, "i s i", oexcel, "Workbooks", sb_get);
  36.   scriba_CallArgEx(pProgram, fn2, argr, 3, arg);
  37.   DIM unsigned long AS oWorkBook = argr[0].v.l;
  38.   arg = scriba_NewSbArgs(pProgram, "i s i", oWorkBook, "Add", sb_call);
  39.   scriba_CallArgEx(pProgram, fn2, argr, 3, arg);
  40.   DIM unsigned long AS oExcelWorkbook = argr[0].v.l;
  41.   arg = scriba_NewSbArgs(pProgram, "i s i i", oExcelWorkbook, "Worksheets", sb_get, 1);
  42.   scriba_CallArgEx(pProgram, fn2, argr, 4, arg);
  43.   DIM unsigned long AS oExcelSheet = argr[0].v.l;
  44.   DIM unsigned long AS oCell;
  45.   DIM char AS cell_text[16];
  46.   DEF_FOR (i = 1 TO i <= 10 STEP INCR i)
  47.   BEGIN_FOR
  48.     DEF_FOR (j = 1 TO j <= 10 STEP INCR j)
  49.     BEGIN_FOR
  50.       arg = scriba_NewSbArgs(pProgram, "i s i i i", oExcelSheet, "Cells", sb_get, i, j);
  51.       scriba_CallArgEx(pProgram, fn2, argr, 5, arg);
  52.       oCell = argr[0].v.l;
  53.       sprintf(cell_text, "test-%i-%i", i, j);
  54.       arg = scriba_NewSbArgs(pProgram, "i s i s",  oCell, "Value", sb_let, cell_text);
  55.       scriba_CallArgEx(pProgram, fn2, argr, 4, arg);
  56.       >> Release oCell before next assignment
  57.       arg = scriba_NewSbArgs(pProgram, "i", oCell);
  58.       scriba_CallArgEx(pProgram, fn3, argr, 1, arg);
  59.     NEXT
  60.   NEXT
  61.   arg = scriba_NewSbArgs(pProgram, "i s i s", oExcelWorkbook, "SaveAs", sb_call, "C:\\ScriptBASIC\\cbasic\\CBASIC_Excel.xls");
  62.   scriba_CallArgEx(pProgram, fn2, argr, 4, arg);
  63.   arg = scriba_NewSbArgs(pProgram, "i s i", oExcelWorkbook, "Close", sb_call);
  64.   scriba_CallArgEx(pProgram, fn2, argr, 3, arg);
  65.   arg = scriba_NewSbArgs(pProgram, "i s i", oexcel, "Quit", sb_call);
  66.   scriba_CallArgEx(pProgram, fn2, argr, 3, arg);
  67.  
  68.   PRINT("Spreadsheet Created\n");
  69.  
  70.   arg = scriba_NewSbArgs(pProgram, "i", oExcelSheet);
  71.   scriba_CallArgEx(pProgram, fn3, argr, 1, arg);
  72.   arg = scriba_NewSbArgs(pProgram, "i", oExcelWorkbook);
  73.   scriba_CallArgEx(pProgram, fn3, argr, 1, arg);
  74.   arg = scriba_NewSbArgs(pProgram, "i", oWorkBook);
  75.   scriba_CallArgEx(pProgram, fn3, argr, 1, arg);
  76.   arg = scriba_NewSbArgs(pProgram, "i", oexcel);
  77.   scriba_CallArgEx(pProgram, fn3, argr, 1, arg);
  78.  
  79.   scriba_DestroySbArgs(pProgram, arg, 5);
  80.   scriba_DestroySbArgs(pProgram, argr, 1);
  81.   scriba_destroy(pProgram);
  82.  
  83.   RETURN_FUNCTION(0);
  84. END_FUNCTION  
  85.  


C:\ScriptBASIC\cbasic>cbasic_excel
Spreadsheet Created

C:\ScriptBASIC\cbasic>


This is the C source after the pre-processor expansion of Defines and Macros for the CBASIC program above.

Code: C
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <getopt.h>
  5. #include "scriba.h"
  6. #include "cbasic.h"
  7.  
  8. int main (int argc, char** argv)
  9. {
  10.   pSbProgram pProgram;
  11.   pSbData arg;
  12.   pSbData argr;
  13.   int sb_call = 1;
  14.   int sb_get = 2;
  15.   int sb_let = 4;
  16.   int sb_set = 8;
  17.   int i, j;
  18.   char src[] = "IMPORT sbembed.sbi\n";
  19.  
  20.   pProgram = scriba_new(malloc,free);
  21.   scriba_LoadConfiguration(pProgram, "C:\\Windows\\SCRIBA.INI");
  22.   scriba_SetFileName(pProgram, "none");
  23.   scriba_LoadProgramString(pProgram, src, strlen(src));
  24.   scriba_Run(pProgram, "");
  25.  
  26.   argr = scriba_NewSbArgs(pProgram,"u");
  27.   int fn1 = scriba_LookupFunctionByName(pProgram, "main::sb_create");
  28.   int fn2 = scriba_LookupFunctionByName(pProgram, "main::sb_cbn");
  29.   int fn3 = scriba_LookupFunctionByName(pProgram, "main::sb_release");
  30.   arg = scriba_NewSbArgs(pProgram, "s", "Excel.Application");
  31.   scriba_CallArgEx(pProgram, fn1, argr, 1, arg);
  32.   unsigned long oexcel = argr[0].v.l;
  33.   arg = scriba_NewSbArgs(pProgram, "i s i", oexcel, "Workbooks", sb_get);
  34.   scriba_CallArgEx(pProgram, fn2, argr, 3, arg);
  35.   unsigned long oWorkBook = argr[0].v.l;
  36.   arg = scriba_NewSbArgs(pProgram, "i s i", oWorkBook, "Add", sb_call);
  37.   scriba_CallArgEx(pProgram, fn2, argr, 3, arg);
  38.   unsigned long oExcelWorkbook = argr[0].v.l;
  39.   arg = scriba_NewSbArgs(pProgram, "i s i i", oExcelWorkbook, "Worksheets", sb_get, 1);
  40.   scriba_CallArgEx(pProgram, fn2, argr, 4, arg);
  41.   unsigned long oExcelSheet = argr[0].v.l;
  42.   unsigned long oCell;
  43.   char cell_text[16];
  44.   for (i = 1 ; i <= 10 ; ++ i)
  45.   {
  46.     for (j = 1 ; j <= 10 ; ++ j)
  47.     {
  48.       arg = scriba_NewSbArgs(pProgram, "i s i i i", oExcelSheet, "Cells", sb_get, i, j);
  49.       scriba_CallArgEx(pProgram, fn2, argr, 5, arg);
  50.       oCell = argr[0].v.l;
  51.       sprintf(cell_text, "test-%i-%i", i, j);
  52.       arg = scriba_NewSbArgs(pProgram, "i s i s", oCell, "Value", sb_let, cell_text);
  53.       scriba_CallArgEx(pProgram, fn2, argr, 4, arg);
  54.       arg = scriba_NewSbArgs(pProgram, "i", oCell);
  55.       scriba_CallArgEx(pProgram, fn3, argr, 1, arg);
  56.     }
  57.   }
  58.   arg = scriba_NewSbArgs(pProgram, "i s i s", oExcelWorkbook, "SaveAs", sb_call, "C:\\ScriptBASIC\\cbasic\\CBASIC_Excel.xls");
  59.   scriba_CallArgEx(pProgram, fn2, argr, 4, arg);
  60.   arg = scriba_NewSbArgs(pProgram, "i s i", oExcelWorkbook, "Close", sb_call);
  61.   scriba_CallArgEx(pProgram, fn2, argr, 3, arg);
  62.   arg = scriba_NewSbArgs(pProgram, "i s i", oexcel, "Quit", sb_call);
  63.   scriba_CallArgEx(pProgram, fn2, argr, 3, arg);
  64.  
  65.   printf("Spreadsheet Created\n");
  66.  
  67.   arg = scriba_NewSbArgs(pProgram, "i", oExcelSheet);
  68.   scriba_CallArgEx(pProgram, fn3, argr, 1, arg);
  69.   arg = scriba_NewSbArgs(pProgram, "i", oExcelWorkbook);
  70.   scriba_CallArgEx(pProgram, fn3, argr, 1, arg);
  71.   arg = scriba_NewSbArgs(pProgram, "i", oWorkBook);
  72.   scriba_CallArgEx(pProgram, fn3, argr, 1, arg);
  73.   arg = scriba_NewSbArgs(pProgram, "i", oexcel);
  74.   scriba_CallArgEx(pProgram, fn3, argr, 1, arg);
  75.  
  76.   scriba_DestroySbArgs(pProgram, arg, 5);
  77.   scriba_DestroySbArgs(pProgram, argr, 1);
  78.   scriba_destroy(pProgram);
  79.  
  80.   return(0);
  81. }
  82.  
Pages: 1 [2] 3 4 ... 10