Author Topic: ScriptBasic Core Windows 32 bit Install  (Read 346 times)

Support

  • Administrator
  • *****
  • Posts: 13
    • View Profile
ScriptBasic Core Windows 32 bit Install
« on: May 25, 2021, 10:07:09 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
« Last Edit: May 26, 2021, 12:54:06 am by Support »

Support

  • Administrator
  • *****
  • Posts: 13
    • View Profile
Re: ScriptBasic Core Windows 32 bit - CIO
« Reply #1 on: May 25, 2021, 10:08:22 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.  

Support

  • Administrator
  • *****
  • Posts: 13
    • View Profile
Re: ScriptBasic Core Windows 32 bit - Sage 100 BOI
« Reply #2 on: May 25, 2021, 10:22:13 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>


Support

  • Administrator
  • *****
  • Posts: 13
    • View Profile
Re: ScriptBasic Core Windows 32 bit - COM Excel
« Reply #3 on: May 25, 2021, 10:24:16 pm »
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.  

Support

  • Administrator
  • *****
  • Posts: 13
    • View Profile
Re: ScriptBasic Core Windows 32 bit - cURL
« Reply #4 on: May 25, 2021, 10:25:19 pm »
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>


Support

  • Administrator
  • *****
  • Posts: 13
    • View Profile
Re: ScriptBasic Core Windows 32 bit - FFI
« Reply #5 on: May 25, 2021, 10:26:23 pm »
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>


Support

  • Administrator
  • *****
  • Posts: 13
    • View Profile
Re: ScriptBasic Core Windows 32 bit - ODBC
« Reply #6 on: May 25, 2021, 10:27:14 pm »
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>


Support

  • Administrator
  • *****
  • Posts: 13
    • View Profile
Re: ScriptBasic Core Windows 32 bit - Asynchronous Thread
« Reply #7 on: May 25, 2021, 10:28:00 pm »
This example creates a ScriptBasic asynchronous thread from a string of source code, sets / gets variables and calls a function.

Code: Script BASIC
  1. ' SBT - Create and call child process script as text source
  2.  
  3. IMPORT sbt.sbi
  4.  
  5. sb_code = """
  6. FUNCTION prtvars(a, b, c)
  7.  PRINT a,"\\n"
  8.  PRINT FORMAT("%g\\n", b)
  9.  PRINT c,"\\n"
  10.  prtvars = "Function Return"
  11. END FUNCTION
  12.  
  13. a = 0
  14. b = 0
  15. c = ""
  16. """
  17.  
  18. sb = SB_New()
  19. SB_Configure sb, "C:/Windows/SCRIBA.INI"
  20. SB_Loadstr sb, sb_code
  21. SB_NoRun sb
  22. ' Call function before running script
  23. funcrtn = SB_CallSubArgs(sb,"main::prtvars", 123, 1.23, "One, Two, Three")
  24. PRINT funcrtn,"\n"
  25. ' Run script initializing globals
  26. SB_Run sb, ""
  27. ' Assign variables values
  28. SB_SetInt sb, "main::a", 321
  29. SB_SetDbl sb, "main::b", 32.1
  30. SB_SetStr sb, "main::c", "Three,Two,One" & CHR(0)
  31. ' Call function again with variables assigned in the previous step
  32. SB_CallSubArgs sb, "main::prtvars", _
  33.           SB_GetVar(sb, "main::a"), _
  34.           SB_GetVar(sb, "main::b"), _
  35.           SB_GetVar(sb, "main::c")
  36. SB_Destroy sb
  37.  


C:\sb_build\examples>sbc sbt_demo.sb
123
1.23
One, Two, Three
Function Return
321
32.1
Three,Two,One

C:\sb_build\examples>


Support

  • Administrator
  • *****
  • Posts: 13
    • View Profile
Re: ScriptBasic Core Windows 32 bit - Synchronous Thread
« Reply #8 on: May 25, 2021, 10:28:58 pm »
This example creates a synchronous thread with the main program running a FOR/NEXT loop in unison with its thread.

sbt_main.sb
Code: Script BASIC
  1. ' SBT Main
  2.  
  3. IMPORT mt.sbi
  4. IMPORT sbt.sbi
  5.  
  6. SB_ThreadStart("sbt_thread.sb", "","C:/Windows/SCRIBA.INI")
  7.  
  8. FOR x = 1 TO 10
  9.   PRINT "M:",x,"\n"
  10.   sb_msSleep(20)
  11. NEXT
  12.  
  13. SB_msSleep(1000)
  14.  
  15. PRINT "Thread ",mt::GetVariable("thread_status"),"\n"
  16.  

sbt_thread.sb
Code: Script BASIC
  1. ' SBT Main
  2.  
  3. IMPORT mt.sbi
  4. IMPORT sbt.sbi
  5.  
  6. SB_ThreadStart("sbt_thread.sb", "","C:/Windows/SCRIBA.INI")
  7.  
  8. FOR x = 1 TO 10
  9.   PRINT "M:",x,"\n"
  10.   sb_msSleep(20)
  11. NEXT
  12.  
  13. SB_msSleep(1000)
  14.  
  15. PRINT "Thread ",mt::GetVariable("thread_status"),"\n"
  16.  


C:\sb_build\examples>sbc sbt_main.sb
T:1
M:1
T:2
M:2
M:3
T:3
T:4
M:4
M:5
T:5
T:6
M:6
T:7
M:7
T:8
M:8
M:9
T:9
T:10
M:10
Thread Completed

C:\sb_build\examples>


Support

  • Administrator
  • *****
  • Posts: 13
    • View Profile
Re: ScriptBasic Core Windows 32 bit - SQLite
« Reply #9 on: May 25, 2021, 10:29:58 pm »
This is an example of using the SQLite extension module.

Code: Script BASIC
  1. IMPORT sqlite.sbi
  2.  
  3. db = sqlite::open("sqlite_demo.db")
  4.  
  5. sqlite::execute(db,"create table demo (someval integer, sometxt text);")
  6. sqlite::execute(db,"insert into demo values (123,'hello');")
  7. sqlite::execute(db, "INSERT INTO demo VALUES (234, 'cruel');")
  8. sqlite::execute(db, "INSERT INTO demo VALUES (345, 'world');")
  9.  
  10. stmt = sqlite::query(db,"SELECT * FROM demo")
  11. WHILE sqlite::row(stmt) = sqlite::SQLITE3_ROW
  12.   IF sqlite::fetchhash(stmt, column) THEN
  13.     PRINT column{"someval"},"\t-\t",column{"sometxt"},"\n"
  14.   END IF
  15. WEND
  16.  
  17. sqlite::close(db)
  18.  


C:\sb_build\examples>sbc sqlite_demo.sb
123     -       hello
234     -       cruel
345     -       world

C:\sb_build\examples>


Support

  • Administrator
  • *****
  • Posts: 13
    • View Profile
Re: ScriptBasic Core Windows 32 bit - Embedding
« Reply #10 on: May 25, 2021, 11:27:04 pm »
Here is my Hello World for ScriptBasic embedding. I typically IMPORT the script resources I need for the project as a source string for ScriptBasic to run.

Code: C
  1. // gcc for_embed.c -I C:\\sbgcc\\source ..\\lib\\libscriba.dll -lpthread -o for_embed
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <getopt.h>
  7. #include "scriba.h"
  8.  
  9. int main (int argc, char** argv)
  10. {
  11.   pSbProgram pProgram;
  12.   char src[] = "FOR i = 1 TO 5\nPRINT i,\"\\n\"\nNEXT\n";
  13.  
  14.   pProgram = scriba_new(malloc,free);
  15.   scriba_SetFileName(pProgram, "none");
  16.   scriba_LoadProgramString(pProgram, src, strlen(src));
  17.   scriba_Run(pProgram, "");
  18.  
  19.   scriba_destroy(pProgram);
  20.  
  21.   return(0);
  22. }  
  23.  


C:\sb_build\examples>gcc for_embed.c -I C:\\sbgcc\\source ..\\lib\\libscriba.dll -lpthread -o for_embed

C:\sb_build\examples>for_embed
1
2
3
4
5

C:\sb_build\examples>