BASIC Developer & Support Resources > Scripting Languages

ScriptBasic Core Windows 32 bit Install

<< < (2/3) > >>

John:
This example uses the DYC extension module to make a dynamic FFI call to the Windows MessageBox API function.


--- Code: Script BASIC ---' DYC - FFI Extension DECLARE SUB DLL ALIAS "dyc" LIB "dyc" PRINT DLL("ms,i,USER32.DLL,MessageBox,PZZL", 0, "Message Text", "Title", 3) '""" Return ValuesTitlebar Exit = 2Yes = 6No = 7Cancel = 2""" 

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

John:
This example uses the ODBC extension module to get the customers from the Sage 100 ABC demo company.


--- Code: Script BASIC ---' Sage 100 Customers - ABC Demo (ProvideX ODBC Driver) IMPORT odbc.sbi dbh = odbc::RealConnect("SOTAMAS90","","")odbc::Query(dbh,"SELECT * FROM AR_Customer") WHILE odbc::FetchHash(dbh, column)  PRINT column{"CustomerNo"}," - ",column{"CustomerName"}," - ",column{"TelephoneNo"},"\n"WEND odbc::Close(dbh) 

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>

John:
This example creates a ScriptBasic asynchronous thread from a string of source code, sets / gets variables and calls a function.


--- Code: Script BASIC ---' SBT - Create and call child process script as text source IMPORT sbt.sbi sb_code = """FUNCTION prtvars(a, b, c)  PRINT a,"\\n"  PRINT FORMAT("%g\\n", b)  PRINT c,"\\n"  prtvars = "Function Return"END FUNCTION a = 0b = 0c = """"" sb = SB_New()SB_Configure sb, "C:/Windows/SCRIBA.INI"SB_Loadstr sb, sb_codeSB_NoRun sb' Call function before running scriptfuncrtn = SB_CallSubArgs(sb,"main::prtvars", 123, 1.23, "One, Two, Three")PRINT funcrtn,"\n"' Run script initializing globalsSB_Run sb, ""' Assign variables valuesSB_SetInt sb, "main::a", 321SB_SetDbl sb, "main::b", 32.1SB_SetStr sb, "main::c", "Three,Two,One" & CHR(0)' Call function again with variables assigned in the previous stepSB_CallSubArgs sb, "main::prtvars", _          SB_GetVar(sb, "main::a"), _          SB_GetVar(sb, "main::b"), _          SB_GetVar(sb, "main::c")SB_Destroy sb 

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>

John:
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 ---' SBT Main IMPORT mt.sbiIMPORT sbt.sbi SB_ThreadStart("sbt_thread.sb", "","C:/Windows/SCRIBA.INI") FOR x = 1 TO 10  PRINT "M:",x,"\n"  sb_msSleep(20)NEXT SB_msSleep(1000) PRINT "Thread ",mt::GetVariable("thread_status"),"\n" 
sbt_thread.sb

--- Code: Script BASIC ---' SBT Main IMPORT mt.sbiIMPORT sbt.sbi SB_ThreadStart("sbt_thread.sb", "","C:/Windows/SCRIBA.INI") FOR x = 1 TO 10  PRINT "M:",x,"\n"  sb_msSleep(20)NEXT SB_msSleep(1000) PRINT "Thread ",mt::GetVariable("thread_status"),"\n" 

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>

John:
This is an example of using the SQLite extension module.


--- Code: Script BASIC ---IMPORT sqlite.sbi db = sqlite::open("sqlite_demo.db") sqlite::execute(db,"create table demo (someval integer, sometxt text);")sqlite::execute(db,"insert into demo values (123,'hello');")sqlite::execute(db, "INSERT INTO demo VALUES (234, 'cruel');")sqlite::execute(db, "INSERT INTO demo VALUES (345, 'world');") stmt = sqlite::query(db,"SELECT * FROM demo")WHILE sqlite::row(stmt) = sqlite::SQLITE3_ROW  IF sqlite::fetchhash(stmt, column) THEN    PRINT column{"someval"},"\t-\t",column{"sometxt"},"\n"  END IFWEND sqlite::close(db) 

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

C:\sb_build\examples>

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version