1. Introduction
Compiling this documentation executes a series of ScriptBasic programs and gets both the source code and the result into the final documentation. The reason for this is to have regression test for each new version of ScriptBasic more or less documented.
Some regression test can not be performed from this documentation compilation. In such case the source file is still included into this documentation but the program is not executes. These are CGI programs, console IO testing programs or some programs that require more interactivity than just stdin input and stdout output.
This documentation was created using
ScriptBasic v1.0
Variation >>STANDARD<< build 26
Magic value 859001651
Node size is 16
Extension interface version is 10
Compilation: Oct 13 2001 16:01:06
Executable: e:\ScriptBasic\bin\scriba.exe
2.1. testnt.bas
This test some functions of the module NT.
Example testnt.bas :
print nt::RegRead("HKLM\\SOFTWARE\\SCRIPTBASIC\\CONFIG"),"\n"
print nt::RegRead("HKLM\\SOFTWARE\\SCRIPTBASIC\\DWORD"),"\n"
print nt::RegRead("HKLM\\SOFTWARE\\SCRIPTBASIC\\BIN"),"\n"
' nt::RegDel "HKLM\\SOFTWARE\\SCRIPTBASIC\\BIN"
nt::RegWrite "HKLM\\SOFTWARE\\SCRIPTBASIC\\BIN1","kakukk"
nt::RegWrite "HKLM\\SOFTWARE\\SCRIPTBASIC\\DWORD1",614
nt::RegWrite "HKLM\\SOFTWARE\\SCRIPTBASIC\\" , "default value"
' nt::RegWrite "HKLM\\SOFTWARE\\SCRIPTBASIC\\SUB\\DWORD1",614
import nt.bas
Result executing testnt.bas :
t:\MyProjects\sb\source\scriba.conf
undef
undef
Possible error messages sent to stderr:
The result printed should be the full path to the configuration file of the actual installation and undef twice.
After executing this script check the Windows NT registry to see that the sample program has written some information into it.
2.2. reftest.bas
This program generated access violation until v1.0b26. This was because ScriptBasic handled variable references to other variables in an extremely simple manner.
Example reftest.bas :
sub test(a)
undef q
print a
end sub
q[1] = 1
test q[1]
print q
Result executing reftest.bas :
1undef
Possible error messages sent to stderr:
2.3. const.bas
This program test the difference local (module local) and global constants.
Example const.bas :
sub TestSub
const c = "c "
print " values in TestSub=",a,b,c,"\n"
var a
print "a in sub=",a,"\n"
end sub
print "values in the module=",a,b,c,"\n"
print "values called from within the module:\n"
TestSub
var a
print "a in module=",a,"\n"
end module
print "values outside the module=",a,b,c,"\n"
print "values called from outside the module:\n"
TEST::TestSub
var a
print "a in global=",a,"\n"
module TEST
a = "VARIABLE"
Global Const a = "a "
Const b = "b "
Result executing const.bas :
values in the module=a b undef
values called from within the module:
values in TestSub=a b c
a in sub=VARIABLE
a in module=VARIABLE
values outside the module=a undefundef
values called from outside the module:
values in TestSub=a b c
a in sub=VARIABLE
a in global=undef
Possible error messages sent to stderr:
Example commandline.bas :
' This program demonstrates the command function
' start the program using the command line:
' scriba commandline.bas a b c d e f
'
print "The command line was:\n",command(),"\n"
2.5. gdtest.bas
This program creates a file `test.png' with some graphics in it.
Example gdtest.bas :
brush = gd::Create(10,10)
white = gd::Color(brush,255,255,255)
black = gd::Color(brush,0,240,0)
gd::Line brush,0,0,10,10,black
gd::Line brush,0,10,10,0,black
' gd::SavePng brush,"brush.png"
image = gd::Create(400,300)
white = gd::Color(image,255,255,255)
gd::SetTransparentColor image,white
black = gd::Color(image,0,0,0)
red = gd::Color(image,255,0,0)
blue = gd::Color(image,0,0,255)
green = gd::Color(image,0,255,0)
gd::Point image,0,0,black
gd::Rectangle image,200,50,250,100,red
gd::FilledRectangle image,225,75,275,125,green
gd::Rectangle image,324,190,376,290,black
gd::SetTile image,brush
' caused stack overflow on a fine NT? Should be some poor implementation
'gd::FillToBorder image,325,191,black,gd::Tiled
gd::Circle image,350,50,40,blue
gd::FillToBorder image,350,50,blue,green
gd::Fill image,201,51,blue
gd::SetBrush image,brush
gd::Line image,300,200,300,350,gd::Brushed
gd::SetColor image,black
gd::SetFont image,gd::FontTiny
gd::print image,0,0,"THIS PICTURE WAS CREATED FROM ScriptBasic USING THE MODULE GD/PNG"
gd::print image,0,10,"x=",gd::SizeX(image)," y=",gd::SizeY(image)
gd::print image,100,100,"Tiny ",12*3+55
gd::SetFont image,gd::FontSmall
gd::print image,100,120,"Small ",55*63
gd::SetFont image,gd::FontMedium
gd::print image,100,150,"Medium ",24/19
gd::SetFont image,gd::FontLarge
gd::print image,100,190,"Large ",sin(3.1)
gd::SetFont image,gd::FontGiant
gd::print image,100,240,"Giant ",log(1000)
for i=0 to 65 step 5
gd::Line image,i,20,65-i,75
next i
LineStyle[0] = black
LineStyle[1] = black
LineStyle[2] = undef
LineStyle[3] = undef
LineStyle[4] = red
LineStyle[5] = green
LineStyle[6] = blue
LineStyle[7] = undef
LineStyle[8] = red
LineStyle[9] = red
gd::LineStyle image,LineStyle
gd::Line image,0,90,100,90,undef
for i=0 to 65 step 5
gd::Line image,i,100,65-i,165,undef
next i
ImagePng = gd::Png(image)
gd::Destroy image
fn = 0
open "test.png" for output as fn
binmode fn
print#fn,ImagePng
undef ImagePng
close#fn
print "donez\n"
import gd.bas
Example asc.bas :
print asc("ALMA")
print
print asc("00")
print
print asc(undef)
print
Result executing asc.bas :
65
48
undef
Possible error messages sent to stderr:
Example replace.bas :
print Replace("alabama mama", "a","x",3,5)
print
end
OriginalString = "a-a-a-a-"
StringToReplace = "a"
ReplaceString ="KURTA"
for i=-1 to 5
print Replace(OriginalString,StringToReplace,ReplaceString,i)
print
next i
print "---------\n"
print Replace(OriginalString,StringToReplace,ReplaceString)
print
for i=-1 to 5
print Replace(OriginalString,StringToReplace,ReplaceString,i,3)
print
next i
print "---------\n"
print Replace(OriginalString,StringToReplace,ReplaceString,undef,3)
print
Result executing replace.bas :
alabxmx mxma
Possible error messages sent to stderr:
Example replace_bug1.bas :
print replace("abcd","bc","x"),"\n"
Result executing replace_bug1.bas :
axd
Possible error messages sent to stderr:
Example replace_bug2.bas :
print replace("abcd","b","x"),"\n"
print replace("abcd","bc","xx"),"\n"
print replace("abcd","b","xx"),"\n"
print replace("abcd","bc","x"),"\n"
Result executing replace_bug2.bas :
axcd
axxd
axxcd
axd
Possible error messages sent to stderr:
Example replace_bug3.bas :
' axcd
' axxcd
' axxc
' axx
'
' axcd
' axxd
' axxcd
' axx
print replace("abcd","b","x"),"\n"
print replace("abcd","b","xx"),"\n"
print replace("abcd","bc","xx"),"\n"
print replace("abcd","bc","x"),"\n"
print"\n"
print replace("abcd","b","x"),"\n"
print replace("abcd","bc","xx"),"\n"
print replace("abcd","b","xx"),"\n"
print replace("abcd","bc","x"),"\n"
Result executing replace_bug3.bas :
axcd
axxd
axxcd
axd
axcd
axxcd
axxd
axd
Possible error messages sent to stderr:
Example stringfunexa.bas :
' This concatenation will result "65"
a = 6 & 5
' the first character of the string "65" is used
q = STRING(5,a)
' val(65) on the other hand is "A"
w = STRING(5,val(a))
print "This should print 66666AAAAA\n"
print q,w
Result executing stringfunexa.bas :
This should print 66666AAAAA
66666AAAAA
Possible error messages sent to stderr:
Example scompare.bas :
print a{"KAKUKK"},nl
option compare sbCaseInSensitive
const nl="\n"
a{"kakukk"} ="birka"
a{"mukik"} = "hurka"
a{"mukak"} = "hurki"
Result executing scompare.bas :
birka
Possible error messages sent to stderr:
Example testcall.bas :
sub MySub(a,b,c)
ByVal a,b,c
if not isdefined(a) then a = "-"
if not isdefined(b) then b = "-"
if not isdefined(c) then c = "-"
print a," ",b," ",c
print "\n"
end sub
MySub(1,2,3)
MySub 2,3,4
MySub(3),4,5
MySub 4,(5),6
MySub
MySub()
MySub(3)
Call MySub(1,2,3)
Call MySub 2,3,4
Call MySub(3),4,5
Call MySub 4,(5),6
Call MySub
Call MySub()
Call MySub(3)
Call MySub(1,2,3)
Call MySub 2,3,4
Call MySub(3),4,5
Call MySub 4,(5),6
Call MySub
Call MySub()
Call MySub(3)
Result executing testcall.bas :
1 2 3
2 3 4
3 4 5
4 5 6
- - -
- - -
3 - -
1 2 3
2 3 4
3 4 5
4 5 6
- - -
- - -
3 - -
1 2 3
2 3 4
3 4 5
4 5 6
- - -
- - -
3 - -
Possible error messages sent to stderr:
Example recurse.bas :
print "Starting calculate 10 for the number ",x,"\n"
if x = 10 then
Calculate10 = x
else
Calculate10 = Calculate10(x+1)
endif
print "Ending calculate 10 for the number ",x,"\n"
end function
Calculate10 1
'
' This function calculates the number 10
' recursively
'
function Calculate10(x)
Result executing recurse.bas :
Starting calculate 10 for the number 1
Starting calculate 10 for the number 2
Starting calculate 10 for the number 3
Starting calculate 10 for the number 4
Starting calculate 10 for the number 5
Starting calculate 10 for the number 6
Starting calculate 10 for the number 7
Starting calculate 10 for the number 8
Starting calculate 10 for the number 9
Starting calculate 10 for the number 10
Ending calculate 10 for the number 10
Ending calculate 10 for the number 9
Ending calculate 10 for the number 8
Ending calculate 10 for the number 7
Ending calculate 10 for the number 6
Ending calculate 10 for the number 5
Ending calculate 10 for the number 4
Ending calculate 10 for the number 3
Ending calculate 10 for the number 2
Ending calculate 10 for the number 1
Possible error messages sent to stderr:
Example msgbox.bas :
nt::MsgBox """This program test the various text boxes.
In the coming message boxes press the various keys as requested by the text
and check on the console window that the program reported the correct
button you pressed. (Only initials are printed.)
""","Initial MsgBox"
splita " |ARI|O|RC|YN|YNC" BY "|" TO buttons
splita " |W|I|Q|S" BY "|" TO marks
for j=lbound(marks) to ubound(marks)
for i=lbound(buttons) to ubound(buttons)
for d=1 to len(buttons[i])
print i," ",buttons[i]," ",j," ",marks[j]," ",d,"\n"
R = nt::MsgBox(buttons[i],marks[j],buttons[i],marks[j],d)
print R
print
next d
next i
next j
import nt.bas
Example testpow.bas :
print "here comes a lot of 1:\n"
print 2 ^ 0
print -2 ^ 0
print 2.0 ^ 0
print -2.0 ^ 0
print "2" ^ 0
print "-2" ^ 0
print "2.0" ^ 0
print "-2.0" ^ 0
print
print "here comes\n2-22-22-22-2\n"
print 2 ^ 1
print -2 ^ 1
print 2.0 ^ 1
print -2.0 ^ 1
print "2" ^ 1
print "-2" ^ 1
print "2.0" ^ 1
print "-2.0" ^ 1
print " and it did!! I told you, believe me!\n"
print "here comes a lot of 4:\n"
print 2 ^ 2
print -2 ^ 2
print 2.0 ^ 2
print -2.0 ^ 2
print "2" ^ 2
print "-2" ^ 2
print "2.0" ^ 2
print "-2.0" ^ 2
print
print 2.2 ^ 2
print
print 2.2 ^ -2, " should be the same as ", 1/ (2.2 ^2)
print
print 2.2 ^ (1/2), " should be same as ",sqr(2.2)
print
print 2.2 ^ -(1/2), " should be same as ", 1/ (2.2^(1/2))
print
print 2.2 ^ (-1/2), " last time this number"
print
print "again with strings\n"
print "2.2" ^ 2
print
print "2.2" ^ -2, " should be the same as ", 1/ (2.2 ^2)
print
print "2.2" ^ "0.5", " should be same as ",sqr(2.2)
print
print "2.2" ^ -(1/2), " should be same as ", 1/ (2.2^(1/2))
print
print "2.2" ^ (-1/2), " last time this number, ... really, I promise..."
print
print "1.0"/sqr("22E-1")
print
print "1.0"/sqr("2.2")
print
print "never trust a program! Any program, ever!\n"
Result executing testpow.bas :
here comes a lot of 1:
11111111
here comes
2-22-22-22-2
2-22-22-22-2 and it did!! I told you, believe me!
here comes a lot of 4:
44444444
4.840000
0.206612 should be the same as 0.206612
1.483240 should be same as 1.483240
0.674200 should be same as 0.674200
0.674200 last time this number
again with strings
4.840000
0.206612 should be the same as 0.206612
1.483240 should be same as 1.483240
0.674200 should be same as 0.674200
0.674200 last time this number, ... really, I promise...
0.674200
0.674200
never trust a program! Any program, ever!
Possible error messages sent to stderr:
Example testproclist.bas :
nt::ListProcesses PS
for i=lbound(PS) to ubound(PS)
for j=0 to 8
print PS[i,j]," "
next j
print "\n"
next i
import nt.bas
Result executing testproclist.bas :
0 0 0 0 1 0 0 0 [System Process]
0 8 0 0 34 0 8 0 System
0 140 0 0 6 8 11 0 SMSS.EXE
0 168 0 0 10 140 13 0 CSRSS.EXE
0 164 0 0 17 140 13 0 WINLOGON.EXE
0 216 0 0 32 164 9 0 SERVICES.EXE
0 228 0 0 14 164 9 0 LSASS.EXE
0 392 0 0 9 216 8 0 svchost.exe
0 420 0 0 11 216 8 0 SPOOLSV.EXE
0 452 0 0 35 216 8 0 svchost.exe
0 492 0 0 2 216 8 0 regsvc.exe
0 508 0 0 7 216 8 0 mstask.exe
0 560 0 0 3 216 8 0 WinMgmt.exe
0 484 0 0 22 216 8 0 inetinfo.exe
0 680 0 0 17 284 8 0 explorer.exe
0 968 0 0 1 680 8 0 v66shell.exe
0 952 0 0 7 680 8 0 realplay.exe
0 956 0 0 3 680 8 0 tsystray.exe
0 944 0 0 1 680 8 0 internat.exe
0 1084 0 0 1 680 8 0 CMD.EXE
0 1112 0 0 4 680 8 0 GPRSWizard.exe
0 868 0 0 3 680 13 0 taskmgr.exe
0 1104 0 0 11 680 8 0 IEXPLORE.EXE
0 1156 0 0 4 392 8 0 MDM.EXE
0 764 0 0 1 1084 8 0 perl.exe
0 908 0 0 1 764 8 0 CMD.EXE
0 824 0 0 1 908 8 0 scriba.exe
Possible error messages sent to stderr:
Example testre.bas :
re::m("alma","a(.*)a")
print re::format("qqq$1qqq")
import re.bas
Result executing testre.bas :
qqqlmqqq
Possible error messages sent to stderr:
2.19. testshutdown.bas
It would be unwise to run this sample program during document compilation. To test it run it from the command line on an NT box an see it shutting down.
Example testshutdown.bas :
nt::ShutDown undef,undef,0,1,1
import nt.bas
Example teststservice.bas :
import nt.bas
print """This test program starts, pauses, continues and stops
the "Removable Storage" service. After each step it waits for user input.
Check the state of the service in the SCM graphical display
pressing F5 to refresh the graphical interface and then
press ENTER in this command window to go on to the next step.
"""
Service$ = "NtmsSvc"
nt::StartService Service$
print Service$ & " has been started\n"
line input wait
nt::PauseService Service$
print Service$ & " is paused...\n"
line input wait
nt::ContinueService Service$
print Service$ & " is continued...\n"
line input wait
nt::StopService Service$
print Service$ & " has been stopped\n"
line input wait
Example callarg_ex.bas :
print a
print
print b
print
print c
print
print d
print
a = "kakukk"
thisfunc = "barna maci"
testvar = "kék maci"
end sub
sub thatfunc(a,b,c,d)
print "testvar is ",testvar
end sub
print "haho!!!\n"
sub thisfunc(a,b,c,d)
Result executing callarg_ex.bas :
haho!!!
Possible error messages sent to stderr:
Example toolstest.bas :
sub PrintVar(V,level)
local i,j
if IsArray(V) Then
for i=lbound(V) to ubound(V)
print space(level)
print i,"->"
PrintVar V[i],level+1
next i
exit sub
end if
print V,"\n"
end sub
for i=1 to 5
for j=1 to 5
for k=1 to 5
a[i,j,k] = i*j*k
next k
next j
next i
s = t::Array2StringMD5(a)
t::SaveString "savedarray.bin",s
s = undef
q = t::LoadString("savedarray.bin")
t::String2ArrayMD5 b,q
PrintVar b,1
import t.bas
Result executing toolstest.bas :
1-> 1-> 1->1
2->2
3->3
4->4
5->5
2-> 1->2
2->4
3->6
4->8
5->10
3-> 1->3
2->6
3->9
4->12
5->15
4-> 1->4
2->8
3->12
4->16
5->20
5-> 1->5
2->10
3->15
4->20
5->25
2-> 1-> 1->2
2->4
3->6
4->8
5->10
2-> 1->4
2->8
3->12
4->16
5->20
3-> 1->6
2->12
3->18
4->24
5->30
4-> 1->8
2->16
3->24
4->32
5->40
5-> 1->10
2->20
3->30
4->40
5->50
3-> 1-> 1->3
2->6
3->9
4->12
5->15
2-> 1->6
2->12
3->18
4->24
5->30
3-> 1->9
2->18
3->27
4->36
5->45
4-> 1->12
2->24
3->36
4->48
5->60
5-> 1->15
2->30
3->45
4->60
5->75
4-> 1-> 1->4
2->8
3->12
4->16
5->20
2-> 1->8
2->16
3->24
4->32
5->40
3-> 1->12
2->24
3->36
4->48
5->60
4-> 1->16
2->32
3->48
4->64
5->80
5-> 1->20
2->40
3->60
4->80
5->100
5-> 1-> 1->5
2->10
3->15
4->20
5->25
2-> 1->10
2->20
3->30
4->40
5->50
3-> 1->15
2->30
3->45
4->60
5->75
4-> 1->20
2->40
3->60
4->80
5->100
5-> 1->25
2->50
3->75
4->100
5->125
Possible error messages sent to stderr:
2.24. trick.bas
This program demonstrates the old trick that had to be used before the operator ByVal was introduced.
Example trick.bas :
#! /usr/bin/scriba
print " "
a=1
call f(a+0)
print a
print
call f(a)
print a
print
function f(x)
x=x+1
end function
Result executing trick.bas :
1
2
Possible error messages sent to stderr:
Example ctestif.bas :
'
' You can change this, but increasing it
' exponentially increases the size of the
' generated program
CONST LIMIT = 8
open "testif.bas" for output as 1
print#1,"""' This program was created by createtestif.bas
' for more information on this program read the comments of that program
"""
print#1,"c=0\nu=0\nfor i=1 to 2"
c=0
for i=1 to LIMIT
for j=0 to 2^i
print#1, "IF ",ABS(odd(j))," THEN\n"
if odd(j) then
print#1, "print ",c,",\" \",c,\" OK\\n\"\nc+=1\n"
c+=1
OKwas = true
else
print#1, """print "FAILED\\n"\nu+=1\n"""
OKwas = 0
endif
BITS = j
for k=1 to i
BITS \= 2
if not OKwas and odd(BITS) then
print#1, "ELSE IF 1 THEN\n"
print#1, "print ",c,",\" \",c,\" OK\\n\"\nc+=1\n"
c+=1
OKwas = true
else
print#1, "ELSE IF ",abs(odd(BITS))," THEN\nprint \"FAILED\\n\"\nu+=1\n"
endif
next k
print#1, "ELSE\n"
if OKwas then
print#1, """print "FAILED\\n"\nu+=1\n"""
else
print#1, "print ",c,",\" \",c,\" OK\\n\"\nc+=1\n"
c+=1
endif
print#1, "END IF\n\n"
next j
print#1, "' ------\n"
next i
print#1, "next\n"
print#1,"print c,\" = ",2*c,"\"\nprint\n"
print#1,"print u,\" = ",0,"\"\nprint\n"
close 1
print "Program testif.bas was created\n"
' FILE: ctestif.bas
'
' This basic program creates another BASIC program to test the IF/ELSEIF/ELSE
' construction executions. This program creates a program that has
' several IF ELSEIF ELSE ENDIF constructs with all possible true/false
' conditions orders. The generated program should NOT write out any "FAILED"
' and should print several OKs
' Finally the the two numbers should match the constants printed counting the printed
' OKs ensuring that all OKs were printed and counting the hopefully zero FAILED prints.
'
Result executing ctestif.bas :
Program testif.bas was created
Possible error messages sent to stderr:
Result executing testif.bas :
0 0 OK
1 1 OK
2 2 OK
3 3 OK
4 4 OK
5 5 OK
6 6 OK
7 7 OK
8 8 OK
9 9 OK
10 10 OK
11 11 OK
12 12 OK
13 13 OK
14 14 OK
15 15 OK
16 16 OK
17 17 OK
18 18 OK
19 19 OK
20 20 OK
21 21 OK
22 22 OK
23 23 OK
24 24 OK
25 25 OK
26 26 OK
27 27 OK
28 28 OK
29 29 OK
30 30 OK
31 31 OK
32 32 OK
33 33 OK
34 34 OK
35 35 OK
36 36 OK
37 37 OK
38 38 OK
39 39 OK
40 40 OK
41 41 OK
42 42 OK
43 43 OK
44 44 OK
45 45 OK
46 46 OK
47 47 OK
48 48 OK
49 49 OK
50 50 OK
51 51 OK
52 52 OK
53 53 OK
54 54 OK
55 55 OK
56 56 OK
57 57 OK
58 58 OK
59 59 OK
60 60 OK
61 61 OK
62 62 OK
63 63 OK
64 64 OK
65 65 OK
66 66 OK
67 67 OK
68 68 OK
69 69 OK
70 70 OK
71 71 OK
72 72 OK
73 73 OK
74 74 OK
75 75 OK
76 76 OK
77 77 OK
78 78 OK
79 79 OK
80 80 OK
81 81 OK
82 82 OK
83 83 OK
84 84 OK
85 85 OK
86 86 OK
87 87 OK
88 88 OK
89 89 OK
90 90 OK
91 91 OK
92 92 OK
93 93 OK
94 94 OK
95 95 OK
96 96 OK
97 97 OK
98 98 OK
99 99 OK
100 100 OK
101 101 OK
102 102 OK
103 103 OK
104 104 OK
105 105 OK
106 106 OK
107 107 OK
108 108 OK
109 109 OK
110 110 OK
111 111 OK
112 112 OK
113 113 OK
114 114 OK
115 115 OK
116 116 OK
117 117 OK
118 118 OK
119 119 OK
120 120 OK
121 121 OK
122 122 OK
123 123 OK
124 124 OK
125 125 OK
126 126 OK
127 127 OK
128 128 OK
129 129 OK
130 130 OK
131 131 OK
132 132 OK
133 133 OK
134 134 OK
135 135 OK
136 136 OK
137 137 OK
138 138 OK
139 139 OK
140 140 OK
141 141 OK
142 142 OK
143 143 OK
144 144 OK
145 145 OK
146 146 OK
147 147 OK
148 148 OK
149 149 OK
150 150 OK
151 151 OK
152 152 OK
153 153 OK
154 154 OK
155 155 OK
156 156 OK
157 157 OK
158 158 OK
159 159 OK
160 160 OK
161 161 OK
162 162 OK
163 163 OK
164 164 OK
165 165 OK
166 166 OK
167 167 OK
168 168 OK
169 169 OK
170 170 OK
171 171 OK
172 172 OK
173 173 OK
174 174 OK
175 175 OK
176 176 OK
177 177 OK
178 178 OK
179 179 OK
180 180 OK
181 181 OK
182 182 OK
183 183 OK
184 184 OK
185 185 OK
186 186 OK
187 187 OK
188 188 OK
189 189 OK
190 190 OK
191 191 OK
192 192 OK
193 193 OK
194 194 OK
195 195 OK
196 196 OK
197 197 OK
198 198 OK
199 199 OK
200 200 OK
201 201 OK
202 202 OK
203 203 OK
204 204 OK
205 205 OK
206 206 OK
207 207 OK
208 208 OK
209 209 OK
210 210 OK
211 211 OK
212 212 OK
213 213 OK
214 214 OK
215 215 OK
216 216 OK
217 217 OK
218 218 OK
219 219 OK
220 220 OK
221 221 OK
222 222 OK
223 223 OK
224 224 OK
225 225 OK
226 226 OK
227 227 OK
228 228 OK
229 229 OK
230 230 OK
231 231 OK
232 232 OK
233 233 OK
234 234 OK
235 235 OK
236 236 OK
237 237 OK
238 238 OK
239 239 OK
240 240 OK
241 241 OK
242 242 OK
243 243 OK
244 244 OK
245 245 OK
246 246 OK
247 247 OK
248 248 OK
249 249 OK
250 250 OK
251 251 OK
252 252 OK
253 253 OK
254 254 OK
255 255 OK
256 256 OK
257 257 OK
258 258 OK
259 259 OK
260 260 OK
261 261 OK
262 262 OK
263 263 OK
264 264 OK
265 265 OK
266 266 OK
267 267 OK
268 268 OK
269 269 OK
270 270 OK
271 271 OK
272 272 OK
273 273 OK
274 274 OK
275 275 OK
276 276 OK
277 277 OK
278 278 OK
279 279 OK
280 280 OK
281 281 OK
282 282 OK
283 283 OK
284 284 OK
285 285 OK
286 286 OK
287 287 OK
288 288 OK
289 289 OK
290 290 OK
291 291 OK
292 292 OK
293 293 OK
294 294 OK
295 295 OK
296 296 OK
297 297 OK
298 298 OK
299 299 OK
300 300 OK
301 301 OK
302 302 OK
303 303 OK
304 304 OK
305 305 OK
306 306 OK
307 307 OK
308 308 OK
309 309 OK
310 310 OK
311 311 OK
312 312 OK
313 313 OK
314 314 OK
315 315 OK
316 316 OK
317 317 OK
318 318 OK
319 319 OK
320 320 OK
321 321 OK
322 322 OK
323 323 OK
324 324 OK
325 325 OK
326 326 OK
327 327 OK
328 328 OK
329 329 OK
330 330 OK
331 331 OK
332 332 OK
333 333 OK
334 334 OK
335 335 OK
336 336 OK
337 337 OK
338 338 OK
339 339 OK
340 340 OK
341 341 OK
342 342 OK
343 343 OK
344 344 OK
345 345 OK
346 346 OK
347 347 OK
348 348 OK
349 349 OK
350 350 OK
351 351 OK
352 352 OK
353 353 OK
354 354 OK
355 355 OK
356 356 OK
357 357 OK
358 358 OK
359 359 OK
360 360 OK
361 361 OK
362 362 OK
363 363 OK
364 364 OK
365 365 OK
366 366 OK
367 367 OK
368 368 OK
369 369 OK
370 370 OK
371 371 OK
372 372 OK
373 373 OK
374 374 OK
375 375 OK
376 376 OK
377 377 OK
378 378 OK
379 379 OK
380 380 OK
381 381 OK
382 382 OK
383 383 OK
384 384 OK
385 385 OK
386 386 OK
387 387 OK
388 388 OK
389 389 OK
390 390 OK
391 391 OK
392 392 OK
393 393 OK
394 394 OK
395 395 OK
396 396 OK
397 397 OK
398 398 OK
399 399 OK
400 400 OK
401 401 OK
402 402 OK
403 403 OK
404 404 OK
405 405 OK
406 406 OK
407 407 OK
408 408 OK
409 409 OK
410 410 OK
411 411 OK
412 412 OK
413 413 OK
414 414 OK
415 415 OK
416 416 OK
417 417 OK
418 418 OK
419 419 OK
420 420 OK
421 421 OK
422 422 OK
423 423 OK
424 424 OK
425 425 OK
426 426 OK
427 427 OK
428 428 OK
429 429 OK
430 430 OK
431 431 OK
432 432 OK
433 433 OK
434 434 OK
435 435 OK
436 436 OK
437 437 OK
438 438 OK
439 439 OK
440 440 OK
441 441 OK
442 442 OK
443 443 OK
444 444 OK
445 445 OK
446 446 OK
447 447 OK
448 448 OK
449 449 OK
450 450 OK
451 451 OK
452 452 OK
453 453 OK
454 454 OK
455 455 OK
456 456 OK
457 457 OK
458 458 OK
459 459 OK
460 460 OK
461 461 OK
462 462 OK
463 463 OK
464 464 OK
465 465 OK
466 466 OK
467 467 OK
468 468 OK
469 469 OK
470 470 OK
471 471 OK
472 472 OK
473 473 OK
474 474 OK
475 475 OK
476 476 OK
477 477 OK
478 478 OK
479 479 OK
480 480 OK
481 481 OK
482 482 OK
483 483 OK
484 484 OK
485 485 OK
486 486 OK
487 487 OK
488 488 OK
489 489 OK
490 490 OK
491 491 OK
492 492 OK
493 493 OK
494 494 OK
495 495 OK
496 496 OK
497 497 OK
498 498 OK
499 499 OK
500 500 OK
501 501 OK
502 502 OK
503 503 OK
504 504 OK
505 505 OK
506 506 OK
507 507 OK
508 508 OK
509 509 OK
510 510 OK
511 511 OK
512 512 OK
513 513 OK
514 514 OK
515 515 OK
516 516 OK
517 517 OK
0 518 OK
1 519 OK
2 520 OK
3 521 OK
4 522 OK
5 523 OK
6 524 OK
7 525 OK
8 526 OK
9 527 OK
10 528 OK
11 529 OK
12 530 OK
13 531 OK
14 532 OK
15 533 OK
16 534 OK
17 535 OK
18 536 OK
19 537 OK
20 538 OK
21 539 OK
22 540 OK
23 541 OK
24 542 OK
25 543 OK
26 544 OK
27 545 OK
28 546 OK
29 547 OK
30 548 OK
31 549 OK
32 550 OK
33 551 OK
34 552 OK
35 553 OK
36 554 OK
37 555 OK
38 556 OK
39 557 OK
40 558 OK
41 559 OK
42 560 OK
43 561 OK
44 562 OK
45 563 OK
46 564 OK
47 565 OK
48 566 OK
49 567 OK
50 568 OK
51 569 OK
52 570 OK
53 571 OK
54 572 OK
55 573 OK
56 574 OK
57 575 OK
58 576 OK
59 577 OK
60 578 OK
61 579 OK
62 580 OK
63 581 OK
64 582 OK
65 583 OK
66 584 OK
67 585 OK
68 586 OK
69 587 OK
70 588 OK
71 589 OK
72 590 OK
73 591 OK
74 592 OK
75 593 OK
76 594 OK
77 595 OK
78 596 OK
79 597 OK
80 598 OK
81 599 OK
82 600 OK
83 601 OK
84 602 OK
85 603 OK
86 604 OK
87 605 OK
88 606 OK
89 607 OK
90 608 OK
91 609 OK
92 610 OK
93 611 OK
94 612 OK
95 613 OK
96 614 OK
97 615 OK
98 616 OK
99 617 OK
100 618 OK
101 619 OK
102 620 OK
103 621 OK
104 622 OK
105 623 OK
106 624 OK
107 625 OK
108 626 OK
109 627 OK
110 628 OK
111 629 OK
112 630 OK
113 631 OK
114 632 OK
115 633 OK
116 634 OK
117 635 OK
118 636 OK
119 637 OK
120 638 OK
121 639 OK
122 640 OK
123 641 OK
124 642 OK
125 643 OK
126 644 OK
127 645 OK
128 646 OK
129 647 OK
130 648 OK
131 649 OK
132 650 OK
133 651 OK
134 652 OK
135 653 OK
136 654 OK
137 655 OK
138 656 OK
139 657 OK
140 658 OK
141 659 OK
142 660 OK
143 661 OK
144 662 OK
145 663 OK
146 664 OK
147 665 OK
148 666 OK
149 667 OK
150 668 OK
151 669 OK
152 670 OK
153 671 OK
154 672 OK
155 673 OK
156 674 OK
157 675 OK
158 676 OK
159 677 OK
160 678 OK
161 679 OK
162 680 OK
163 681 OK
164 682 OK
165 683 OK
166 684 OK
167 685 OK
168 686 OK
169 687 OK
170 688 OK
171 689 OK
172 690 OK
173 691 OK
174 692 OK
175 693 OK
176 694 OK
177 695 OK
178 696 OK
179 697 OK
180 698 OK
181 699 OK
182 700 OK
183 701 OK
184 702 OK
185 703 OK
186 704 OK
187 705 OK
188 706 OK
189 707 OK
190 708 OK
191 709 OK
192 710 OK
193 711 OK
194 712 OK
195 713 OK
196 714 OK
197 715 OK
198 716 OK
199 717 OK
200 718 OK
201 719 OK
202 720 OK
203 721 OK
204 722 OK
205 723 OK
206 724 OK
207 725 OK
208 726 OK
209 727 OK
210 728 OK
211 729 OK
212 730 OK
213 731 OK
214 732 OK
215 733 OK
216 734 OK
217 735 OK
218 736 OK
219 737 OK
220 738 OK
221 739 OK
222 740 OK
223 741 OK
224 742 OK
225 743 OK
226 744 OK
227 745 OK
228 746 OK
229 747 OK
230 748 OK
231 749 OK
232 750 OK
233 751 OK
234 752 OK
235 753 OK
236 754 OK
237 755 OK
238 756 OK
239 757 OK
240 758 OK
241 759 OK
242 760 OK
243 761 OK
244 762 OK
245 763 OK
246 764 OK
247 765 OK
248 766 OK
249 767 OK
250 768 OK
251 769 OK
252 770 OK
253 771 OK
254 772 OK
255 773 OK
256 774 OK
257 775 OK
258 776 OK
259 777 OK
260 778 OK
261 779 OK
262 780 OK
263 781 OK
264 782 OK
265 783 OK
266 784 OK
267 785 OK
268 786 OK
269 787 OK
270 788 OK
271 789 OK
272 790 OK
273 791 OK
274 792 OK
275 793 OK
276 794 OK
277 795 OK
278 796 OK
279 797 OK
280 798 OK
281 799 OK
282 800 OK
283 801 OK
284 802 OK
285 803 OK
286 804 OK
287 805 OK
288 806 OK
289 807 OK
290 808 OK
291 809 OK
292 810 OK
293 811 OK
294 812 OK
295 813 OK
296 814 OK
297 815 OK
298 816 OK
299 817 OK
300 818 OK
301 819 OK
302 820 OK
303 821 OK
304 822 OK
305 823 OK
306 824 OK
307 825 OK
308 826 OK
309 827 OK
310 828 OK
311 829 OK
312 830 OK
313 831 OK
314 832 OK
315 833 OK
316 834 OK
317 835 OK
318 836 OK
319 837 OK
320 838 OK
321 839 OK
322 840 OK
323 841 OK
324 842 OK
325 843 OK
326 844 OK
327 845 OK
328 846 OK
329 847 OK
330 848 OK
331 849 OK
332 850 OK
333 851 OK
334 852 OK
335 853 OK
336 854 OK
337 855 OK
338 856 OK
339 857 OK
340 858 OK
341 859 OK
342 860 OK
343 861 OK
344 862 OK
345 863 OK
346 864 OK
347 865 OK
348 866 OK
349 867 OK
350 868 OK
351 869 OK
352 870 OK
353 871 OK
354 872 OK
355 873 OK
356 874 OK
357 875 OK
358 876 OK
359 877 OK
360 878 OK
361 879 OK
362 880 OK
363 881 OK
364 882 OK
365 883 OK
366 884 OK
367 885 OK
368 886 OK
369 887 OK
370 888 OK
371 889 OK
372 890 OK
373 891 OK
374 892 OK
375 893 OK
376 894 OK
377 895 OK
378 896 OK
379 897 OK
380 898 OK
381 899 OK
382 900 OK
383 901 OK
384 902 OK
385 903 OK
386 904 OK
387 905 OK
388 906 OK
389 907 OK
390 908 OK
391 909 OK
392 910 OK
393 911 OK
394 912 OK
395 913 OK
396 914 OK
397 915 OK
398 916 OK
399 917 OK
400 918 OK
401 919 OK
402 920 OK
403 921 OK
404 922 OK
405 923 OK
406 924 OK
407 925 OK
408 926 OK
409 927 OK
410 928 OK
411 929 OK
412 930 OK
413 931 OK
414 932 OK
415 933 OK
416 934 OK
417 935 OK
418 936 OK
419 937 OK
420 938 OK
421 939 OK
422 940 OK
423 941 OK
424 942 OK
425 943 OK
426 944 OK
427 945 OK
428 946 OK
429 947 OK
430 948 OK
431 949 OK
432 950 OK
433 951 OK
434 952 OK
435 953 OK
436 954 OK
437 955 OK
438 956 OK
439 957 OK
440 958 OK
441 959 OK
442 960 OK
443 961 OK
444 962 OK
445 963 OK
446 964 OK
447 965 OK
448 966 OK
449 967 OK
450 968 OK
451 969 OK
452 970 OK
453 971 OK
454 972 OK
455 973 OK
456 974 OK
457 975 OK
458 976 OK
459 977 OK
460 978 OK
461 979 OK
462 980 OK
463 981 OK
464 982 OK
465 983 OK
466 984 OK
467 985 OK
468 986 OK
469 987 OK
470 988 OK
471 989 OK
472 990 OK
473 991 OK
474 992 OK
475 993 OK
476 994 OK
477 995 OK
478 996 OK
479 997 OK
480 998 OK
481 999 OK
482 1000 OK
483 1001 OK
484 1002 OK
485 1003 OK
486 1004 OK
487 1005 OK
488 1006 OK
489 1007 OK
490 1008 OK
491 1009 OK
492 1010 OK
493 1011 OK
494 1012 OK
495 1013 OK
496 1014 OK
497 1015 OK
498 1016 OK
499 1017 OK
500 1018 OK
501 1019 OK
502 1020 OK
503 1021 OK
504 1022 OK
505 1023 OK
506 1024 OK
507 1025 OK
508 1026 OK
509 1027 OK
510 1028 OK
511 1029 OK
512 1030 OK
513 1031 OK
514 1032 OK
515 1033 OK
516 1034 OK
517 1035 OK
1036 = 1036
0 = 0
Possible error messages sent to stderr:
2.26. hostname.bas
This program tests the function hostname(). It prints it on the screen.
Example hostname.bas :
print "The local host name is :", hostname(),"\n"
Result executing hostname.bas :
The local host name is :home-t990r6ichh
Possible error messages sent to stderr:
Example array.bas :
a[5,3]=4
c = a[5]
print a[5,3],c
Result executing array.bas :
4ARRAY@#003643C4
Possible error messages sent to stderr:
Example cbigboy.bas :
print#1, "a=1\n"
for i=1 to 10000
print #1,"a = a +1\nprint a,\"\\n\"\n"
next
close 1
' Run this program to create the BASIC program
' BIGBOY.BAS
'
' Run bigboy with the command line:
' scriba bigboy.bas -o bigboy.bbf
'
' Now you have both the source and the intermediate compiled version
'
' run
' basic bigboy.bas
' and run
' basic bigboy.bbf
' and see the difference in the speed of the startup.
'
open "bigboy.bas" for output as 1
2.29. http.bas
This sample program fetches the opening page of the ScriptBasic site. Because the regression test usually executed on an off-line machine this code is not executed during the compilation of this document.
Example http.bas :
' This is a sample showing how easy to download a
' web page using ScriptBasic
'
open "scriptbasic.com:80" for socket as 1
print#1,"GET / HTTP/1.0\nHost: scriptbasic.com\n\n"
while not eof(1)
line input #1,a
print a
wend
close 1
2.30. kill.bas
This script tests the command kill. To execute it get some harmless process running (like vi or notepad) and get the pid of it using the command ps on UNIX or the task manager under NT kill the process using this program.
After executing the program check that the process is gone.
Example kill.bas :
print "give me a pid to kill!"
line input pid
if kill(pid) then
print "success\n"
else
print "cannot kill\n"
endif
2.31. factime.bas
This program test the different file time settings. This program can run on both UNIX and NT however on UNIX create time is not defined.
Example factime.bas :
print FormatDate("YEAR MON DD HH:mm:ss",FileCreateTime("kill.bas"))
print
print FormatDate("YEAR MON DD HH:mm:ss",FileModifyTime("kill.bas"))
print
print FormatDate("YEAR MON DD HH:mm:ss",FileAccessTime("kill.bas"))
print
set file "kill.bas" createtime=TimeValue(1970,10,2,14,53)
set file "kill.bas" modifytime=TimeValue(1980,10,2,14,53)
set file "kill.bas" accesstime=TimeValue(1990,10,2,14,53)
print "------------------\n"
print FormatDate("YEAR MON DD HH:mm:ss",FileCreateTime("kill.bas"))
print
print FormatDate("YEAR MON DD HH:mm:ss",FileModifyTime("kill.bas"))
print
print FormatDate("YEAR MON DD HH:mm:ss",FileAccessTime("kill.bas"))
print
Result executing factime.bas :
2001 Nov 2 18:59:44
2001 Nov 2 18:59:44
2001 Nov 2 18:59:44
------------------
1970 Oct 2 14:53:0
1980 Oct 2 14:53:0
1990 Oct 2 14:53:0
Possible error messages sent to stderr:
Example funcallexa.bas :
print a,b,c,x
printnl
x = a * b * c
MyFunction = a + b + c
end function
a = MyFunction(1,2,MyFunction(1,1,1))
print a
printnl
function MyFunction(a,b,c)
local x
Result executing funcallexa.bas :
111undef
123undef
6
Possible error messages sent to stderr:
Example instrrev.bas :
a = "alabama mama"
StartPosition = 5000
while IsDefined(StartPosition)
StartPosition = InStrRev(a,"ma",StartPosition)
print StartPosition
print
StartPosition = StartPosition - 1
wend
print InStrRev("almafa","maf")
print
print InStrRev("almafa","alma")
print
print InStrRev("almafa","afa")
print
print InStrRev("almafa","faa")
print
Result executing instrrev.bas :
3
1
4
undef
11
9
6
undef
Possible error messages sent to stderr:
Example instr.bas :
a = "alabama mama"
StartPosition = 1
while IsDefined(StartPosition)
StartPosition = InStr(a,"ma",StartPosition)
print StartPosition
print
StartPosition = StartPosition + 1
wend
print InStr("almafa","maf")
print
print InStr("almafa","alma")
print
print InStr("almafa","afa")
print
print InStr("almafa","faa")
print
Result executing instr.bas :
3
1
4
undef
6
9
11
undef
Possible error messages sent to stderr:
Example strconv.bas :
a = "123"
print a+1
print
a = a-1
print a & "bib"
Result executing strconv.bas :
124
122bib
Possible error messages sent to stderr:
Example like.bas :
Const nl="\n"
a="13*52" like "#*#"
print joker(1)," ",joker(3),nl
a="13*52" like "#~*#"
print joker(1)," ",joker(2),nl
set no joker "*"
a="13*52" like "#*#"
print joker(1)," ",joker(2),nl
Result executing like.bas :
1 52
13 52
13 52
Possible error messages sent to stderr:
Example localexa.bas :
a = 1
call MySub(a+0)
print a
sub MySub(x)
x = x + 1
end sub
Result executing localexa.bas :
1
Possible error messages sent to stderr:
Example lock.bas :
open "lock.bas" for binary as 1
lock #1, write
print "Locked now:"
' line input a
print
lock #1, release
print "unlocked, but still open"
' line input a
print
close 1
print "closed"
print
Result executing lock.bas :
Locked now:
unlocked, but still open
closed
Possible error messages sent to stderr:
Example locktest1.bas :
open "locktest.txt" for output as 1
lock region#1 from 1 to 5 for write
for i=1 to 5
print #1, "A"
next i
print "5 bytes are done\n"
for i=1 to 5
print #1, "B"
next i
print "10 bytes are done first 5 bytes are locked\n"
' line input a
close 1
Result executing locktest1.bas :
5 bytes are done
10 bytes are done first 5 bytes are locked
Possible error messages sent to stderr:
Example locktest2.bas :
open "locktest.txt" for input as 1
line input#1,a
print a
close 1
Result executing locktest2.bas :
AAAAABBBBB
Possible error messages sent to stderr:
Example locktest3.bas :
open "locktest.txt" for random as 1
seek#1,5
for i=1 to 5
print #1, "D"
next i
print "10 bytes are done first 5 bytes are locked\n"
' line input a
close 1
Result executing locktest3.bas :
10 bytes are done first 5 bytes are locked
Possible error messages sent to stderr:
Example mandel1.bas :
function mandel(zre,zim,maxiter)
local x,y,tmp,betrag
local iter
x=0.0
y=0.0
iter=0
betrag=0.0
while iter < maxiter
iter += 1
tmp=x*x-y*y+zre
y=2*x*y+zim
x=tmp
betrag = x*x + y*y
if betrag > 4 then
mandel = iter
exit function
end if
wend
mandel = maxiter
end function
breite=320
hoehe=240
do_work=FALSE
xstart = -1.8
xend = 0.8
ystart = -1.0
yend = 1.0
frame = japi::frame("Variables Mandelbrot")
japi::setborderlayout(frame)
menubar = japi::menubar(frame)
file$ = japi::menu(menubar,"File")
calc = japi::menu(menubar,"Calc")
quit = japi::menuitem(file$,"Quit")
start = japi::menuitem(calc,"Start")
stopp = japi::menuitem(calc,"Stop")
canvas = japi::canvas(frame,breite,hoehe)
japi::pack(frame)
japi::show(frame)
' Waiting for actions
x=-1
y=-1
while true
if do_work then
obj=japi::getaction()
else
obj=japi::nextaction()
endif
if obj = quit then stop
if(obj = start) then
x=-1
y=-1
do_work=TRUE
japi::setnamedcolor(canvas,J_WHITE)
endif
if(obj = stopp) then do_work=FALSE
if(do_work) then
x=(x+1) % breite
if(x = 0)then y=(y+1) % hoehe
if((x = breite-1) and (y = hoehe-1)) then
do_work=FALSE
else
zre = xstart + x*(xend-xstart) / breite
zim = ystart + y*(yend-ystart) / hoehe
it = mandel(zre,zim,512)
japi::setcolor(canvas,(it*11),(it*13),(it*17))
japi::drawpixel(canvas,x,y)
endif
endif
if(obj = canvas)then
breite = japi::getwidth(canvas)
hoehe = japi::getheight(canvas)
x=-1
y=-1
endif
wend
import japi.bas
Example hedbergtest.bas :
print CurDir
print
print IsDirectory(CurDir)
Result executing hedbergtest.bas :
T:\MyProjects\sb\source\html\texi\tmp
-1
Possible error messages sent to stderr:
2.44. onerror.bas
This program tests the error handling of ScriptBasic. It has to print An error has occured, but this is no problem.. In case you uncomment the ON ERROR GOTO statement inside the subroutine the subroutine has to handle the error.
Example onerror.bas :
print "No error has occured in the function"
goto FinishLabel
ErrorLabel:
print "An error has occured inside the sub"
print
FinishLabel:
end sub
on error goto ErrorLabel
ErrorSub
print "No error"
goto FinishLabel
ErrorLabel:
print " An error has occured, but this is no problem."
FinishLabel:
sub ErrorSub
'on error goto ErrorLabel
open "nofile" for input as 1
Result executing onerror.bas :
An error has occured, but this is no problem.
Possible error messages sent to stderr:
2.45. evaorder.bas
This test demonstrates that ScriptBasic evaluates first the left values and then the expression. Therefore this program prints 56.
Example evaorder.bas :
z =55
a[q()] = z
print a[56]
function q
z = z + 1
q = z
end function
Result executing evaorder.bas :
56
Possible error messages sent to stderr:
2.46. misc.bas
This program tries to test several features of the ScriptBasic interpreter. On some configuration it may stop with out of memory. In that case check the configuration file memory limit for each interpreter.
Example misc.bas :
' testing numeric operators
print "Testing numeric operators...\n"
a = 2^3
if a = 8 then
print "Power operator seems to be OK\n"
else
print "Power operator said that 2^3=",a,"\n"
stop
endif
a = 2*5
if a = 10 Then
print "multiply operator seems to be OK\n"
else
print "multiply operator said that 2*5=",a,"\n"
stop
endif
a = 10/2
if a = 5 Then
print "div operator seems to be OK\n"
else
print "div operator said that 10/2=",a,"\n"
stop
endif
print "9/2=",9/2
printnl
print "9\\2=",9\2
printnl
print "9%4=",9%4
printnl
print "1+1=",1+1
printnl
print "6-3=",6-3
printnl
print "6-3+2=",6-3+2
printnl
print "6=6?",6=6
print
print "6=3?",6=3
print
print "3<>3?",3<>3
print
print "2<>3?",2<>3
print
print "2<3?",2<3
print
print "3<2?",3<2
print
print "3>2?",3>2
print
print "2>3?",2>3
print
print "2<=3?",2<=3
print
print "3<=2?",3<=2
print
print "3>=2?",3>=2
print
print "2>=3?",2>=3
print
print "2<=2?",2<=2
print
print "2>=2?",2>=2
print
print "3=",1 or 2
print
print "2=", 3 and 2
print
print "2=", 3 xor 1
print
print "testing string concatenation...\n"
print "a" & "a" & "a" & "a" & "a" & "a" & "a" & "a" & "a" & "a" & "a"
print
print "testing the for loop\n"
for i=1 to 10
print i
next
print
print "testing heavy memory usage via string concatenation...\n"
q = ""
for i = 1 to 1024
q = q & " "
next
print "q is now string of length ",len(q)," bytes\n"
print
print "Creating a one megabyte string concatenating 1024 times a 1K string."
print
print "Be patient...\n"
p = q
q = ""
for i = 1 to 1024
if i%100 = 0 then
print "."
endif
q = q & p
next
print
print "q is now string of length ",len(q)," bytes\n"
print "was it ",1024*1024," bytes?\n"
if 1024*1024 = len(q) then
print "yes it was\n"
else
print "No it is a problem...\n"
stop
endif
' Testing that ScriptBasic is capable printing out constant string
print "print is OK\n"
Result executing misc.bas :
Creating a one megabyte string concatenating 1024 times a 1K string.
Be patient...
....
print is OK
Testing numeric operators...
Power operator seems to be OK
multiply operator seems to be OK
div operator seems to be OK
9/2=4.500000
9\2=4
9%4=1
1+1=2
6-3=3
6-3+2=5
6=6?-1
6=3?0
3<>3?0
2<>3?-1
2<3?-1
3<2?0
3>2?-1
2>3?0
2<=3?-1
3<=2?0
3>=2?-1
2>=3?0
2<=2?-1
2>=2?-1
3=3
2=2
2=2
testing string concatenation...
aaaaaaaaaaa
testing the for loop
12345678910
testing heavy memory usage via string concatenation...
q is now string of length 1024 bytes
Possible error messages sent to stderr:
(0): error &H1:Not enough memory
Example bdbtransact.bas :
DB = bdb::open("alma.db",bdb::BTree,bdb::Create,0)
bdb::BeginTransaction
print "transaction started\n"
Counter = bdb::Get(DB,"COUNTER")
print "Counter is ",Counter,nl
If IsDefined(Counter) Then
Counter = Counter + 1
bdb::Update DB,Counter
print "updated\n "
Else
Counter = 1
bdb::Put DB,"COUNTER",Counter
print "put\n "
End If
bdb::EndTransaction
print "transaction has finished\n"
bdb::close(DB)
' bdb::Drop "alma.db"
include bdb.bas
Const nl = "\n"
Result executing bdbtransact.bas :
transaction started
Counter is 34
updated
transaction has finished
Possible error messages sent to stderr:
2.48. testcio.bas
This program tests the console IO capabilities of the module CIO. This is extremely interactive thus here we list only the source code and not the result. The result is actually series of colorful and flashing console screens.
This program is Windows specific and can not be executed under UNIX.
Example testcio.bas :
cio::SetColor FBlue or BGrey
cio::cls
i = 1
while 1
if i % 2 Then
cio::SetColor FBlue or BGrey
Else
cio::SetColor FBlue or BIntense
End If
Xs = cio::SizeX()
Ys = cio::SizeY()
cio::gotoxy 10,23
print "The console size is : ",Xs," ",Ys,"\n"
print "The possible maximal sizes are: ",cio::PossibleMaxX()," ",cio::PossibleMaxY(),"\n"
print "The actual size is: ",cio::SizeX()," ",cio::SizeY()
cio::SetCursor 50
cio::gotoxy 1,40
for j=1 to 300
cio::SetColor j
print "Q"
next j
sleep 1
if cio::kbhit() then
ch = cio::getch()
cio::gotoxy 10,20
print "Key ",ch," was pressed..."
if ch = 13 then cio::nobreak
if ch = asc("a") then cio::break
end if
cio::gotoxy 10,10
print i
i += 1
print " "
print cio::GetTitle()
cio::SetTitle i
wend
import cio.bas
2.49. concol.bas
This program lists all the possible console character colors on a windows console. This program can not be executed under UNIX
Example concol.bas :
cio::SetColor FWhite
cio::cls
cio::SetTitle "Testing console colors"
for i=1 to 255
cio::gotoxy +(i \ 16) * 4 , +(i % 16) * 2
cio::gotoxy( (i \ 16) * 4 , +(i % 16) * 2 )
cio::gotoxy (i \ 16) * 4 , +(i % 16) * 2
cio::SetColor (i)
j = i
if i < 100 then j = "0" & j
print j
next i
cio::SetColor FWhite
cio::SetCursor 0
i = cio::getch()
print "\nDONEZ\n"
import cio.bas
2.50. compare.bas
This program tests different comparisions.
Example compare.bas :
"""
if "a" = "a" then
print 1
else
print 0
end if
if "a" <> "a" then
print 0
else
print 1
end if
if "a" < "a" then
print 0
else
print 1
end if
if "a" < "b" then
print 1
else
print 0
end if
if "b" < "a" then
print 0
else
print 1
end if
if "a" > "a" then
print 0
else
print 1
end if
if "a" > "b" then
print 0
else
print 1
end if
if "b" > "a" then
print 1
else
print 0
end if
if "a" <= "a" then
print 1
else
print 0
end if
if "a" <= "b" then
print 1
else
print 0
end if
if "b" <= "a" then
print 0
else
print 1
end if
if "a" >= "a" then
print 1
else
print 0
end if
if "a" >= "b" then
print 0
else
print 1
end if
if "b" >= "a" then
print 1
else
print 0
end if
REM comparing different length strings
if "a" = "ab" then
print 0
else
print 1
end if
if "a" <> "ab" then
print 1
else
print 0
end if
if "a" < "ab" then
print 1
else
print 0
end if
if "ab" < "b" then
print 1
else
print 0
end if
if "b" < "ab" then
print 0
else
print 1
end if
if "a" > "ab" then
print 0
else
print 1
end if
if "a" > "bb" then
print 0
else
print 1
end if
if "b" > "ab" then
print 1
else
print 0
end if
if "a" <= "ab" then
print 1
else
print 0
end if
if "ab" <= "b" then
print 1
else
print 0
end if
if "b" <= "ab" then
print 0
else
print 1
end if
if "ab" >= "a" then
print 1
else
print 0
end if
if "ab" >= "b" then
print 0
else
print 1
end if
if "b" >= "ab" _
then
print 1
else
print 0
end if
print "\ntest ended\n"
' note that strings are multi line
print """This program tests different string comparisions.
The result should be a lot of 1
printed. If there is any 0 printed there
is an error in the interpreter.
Result executing compare.bas :
1111111111111111111111111111
test ended
This program tests different string comparisions.
The result should be a lot of 1
printed. If there is any 0 printed there
is an error in the interpreter.
Possible error messages sent to stderr:
2.51. hash.bas
This program tests the hash module.
Example hash.bas :
import hash.bas
Const nl="\n"
h = hash::New()
hash::SetValue h,"evil",666
Zazu = hash::Value(h,"evil")
print Zazu,nl
Zazu = "BILL"
print hash::Value(h,"evil"),nl
hash::Release h
Result executing hash.bas :
Possible error messages sent to stderr:
(0): error &H1:Not enough memory
Example math.bas :
for i=-pi to +pi step pi/20.0
print space((sin(i)+1.0)*30),"*"
print
next i
print "testing the function pow\n"
for i=-20 to 20
print pow(i)
print
next i
'
'
'
print "testing the function exp\n"
for i=-20 to 20
print exp(i)
print
next i
'
'
'
print "testing the function log\n"
for i=0 to 2 step 0.1
print log(i)
print
next i
'
'
'
print "testing the function log10\n"
for i=0 to 2 step 0.1
print log10(i)
print
next i
'
'
'
print "testing the function sin\n"
for i=-pi to +pi step pi/20.0
print sin(i)
print
next i
Result executing math.bas :
testing the function pow
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000001
0.000010
0.000100
0.001000
0.010000
0.100000
1
10
100
1000
10000
100000
1000000
10000000
100000000
1000000000
10000000000.000000
100000000000.000000
1000000000000.000000
10000000000000.000000
100000000000000.000000
1000000000000000.000000
10000000000000000.000000
100000000000000000.000000
1000000000000000000.000000
10000000000000000000.000000
100000000000000000000.000000
testing the function exp
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000001
0.000002
0.000006
0.000017
0.000045
0.000123
0.000335
0.000912
0.002479
0.006738
0.018316
0.049787
0.135335
0.367879
1
2.718282
7.389056
20.085537
54.598150
148.413159
403.428793
1096.633158
2980.957987
8103.083928
22026.465795
59874.141715
162754.791419
442413.392009
1202604.284165
3269017.372472
8886110.520508
24154952.753575
65659969.137331
178482300.963187
485165195.409791
testing the function log
undef
-2.302585
-1.609438
-1.203973
-0.916291
-0.693147
-0.510826
-0.356675
-0.223144
-0.105361
-0.000000
0.095310
0.182322
0.262364
0.336472
0.405465
0.470004
0.530628
0.587787
0.641854
testing the function log10
undef
-1
-0.698970
-0.522879
-0.397940
-0.301030
-0.221849
-0.154902
-0.096910
-0.045757
-0.000000
0.041393
0.079181
0.113943
0.146128
0.176091
0.204120
0.230449
0.255273
0.278754
testing the function sin
-0.000000
-0.156435
-0.309017
-0.453991
-0.587785
-0.707107
-0.809017
-0.891007
-0.951057
-0.987688
-1.000000
-0.987688
-0.951057
-0.891007
-0.809017
-0.707107
-0.587785
-0.453990
-0.309017
-0.156434
0.000000
0.156434
0.309017
0.453990
0.587785
0.707107
0.809017
0.891007
0.951057
0.987688
1.000000
0.987688
0.951057
0.891007
0.809017
0.707107
0.587785
0.453991
0.309017
0.156435
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
Possible error messages sent to stderr:
2.53. mysql.bas
MySQL is usually not started on the development machine where this documentation is compiled, therefore here we only list this code without the result printout.
Example testmysql.bas :
dbh = mysql::Connect("test")
print "The data base handle is: ",dbh,"\n"
' mysql::Shutdown dbh
' print mysql::ErrorMessage(),"\n"
print mysql::Stat(dbh)
print
mysql::query dbh,"delete from users where name='Kakukk'"
print "Affected rows after delete is: ",mysql::AffectedRows(dbh)
print
mysql::query dbh,"insert into users values ('Kakukk',52)"
print "Affected rows after inserting kakukk: ",mysql::AffectedRows(dbh)
print
print "Info is: ",mysql::Info(dbh)
print
mysql::query dbh,"select * from users order by name desc"
print "Affected rows after select: ",mysql::AffectedRows(dbh)
print
' mysql::DataSeek dbh,1
' print
i=0
while mysql::fetcharray(dbh,q)
i=i+1
print i,". ",q[0]," ",q[1]
print
wend
print "Character set name is: ",mysql::CharacterSetName(dbh)
print
mysql::query dbh,"select * from users order by name desc"
print "Affected rows after select: ",mysql::AffectedRows(dbh)
print
' mysql::DataSeek dbh,1
' print
i=0
while mysql::FetchHash(dbh,q)
i=i+1
print i,". "
print
print "name=",q{"name"}
print
print "age=",q{"age"}
print
wend
' mysql::DataSeek dbh,0
on error resume next
mysql::query dbh,"select * from user"
print "Last error is: ",mysql::ErrorMessage(dbh)
print
print "Client info is: ",mysql::GetClientInfo()
print
print "Host info is: ",mysql::GetHostInfo(dbh)
print
print "Proto info is: ",mysql::GetProtoInfo(dbh)
print
print "Server info is: ",mysql::GetServerInfo(dbh)
print
mysql::query dbh,"SHOW PROCESSLIST"
print "Affected rows after show processlistselect: ",mysql::AffectedRows(dbh)
print
i=0
while mysql::fetcharray(dbh,q)
i=i+1
print i,". ",q[0]
' mysql::kill dbh,q[0]
print
wend
print "ping result: ",mysql::Ping(dbh)
print "haho"
print
on error resume next
mysql::Query dbh,"INSERT INTO autoinc values ('huuuh',null)"
print mysql::ErrorMessage(dbh)
print
print mysql::InsertId(dbh)
print
print "Thread id=",mysql::ThreadId(dbh)
print
mysql::kill dbh, mysql::ThreadId(dbh)
mysql::Close(dbh)
import mysql.bas
2.54. sleep.bas
Running this program prints the numbers from 1 to 20 with 1 sec delay between them. Running this program from the documentation compilation increases the document compilation with 20 sec and is useless as we can not check interactively the delay between the printouts. Therefore here we list only the code and the result has to be checked separately.
Example sleep.bas :
for i=1 to 20
print i
print
sleep 1
next i
2.55. time.bas
This program checks the time functions of ScriptBasic.
Example time.bas :
Const nl = "\n"
for i=1 to 5
print i,".\n"
print "The local time is: ",Year,".",Month,".",Day," ",Hour,":",Minute,":",Sec,nl
print "The Greenich mean time is: ",FormatDate("YEAR.MM.DD hh:mm:ss",GmTime()),nl
a = now
b = TimeValue(year,month,day,hour,minute,sec)
print "Local time is sec from Now():",a,nl, _
"Local time in sec from TimeValue(...)",b,nl, _
"The difference should be zero: ",a-b,nl
print "GMT:",GmTime,"=",LocalTimeToGmTime(Time),nl
print "LCT:",Time,"=",GmTimeToLocalTime(GmTime),nl
sleep 1
next i
Result executing time.bas :
1.
The local time is: 2001.11.2 19:59:47
The Greenich mean time is: 2001.11.2 6:59:47
Local time is sec from Now():1004731187
Local time in sec from TimeValue(...)1004731187
The difference should be zero: 0
GMT:1004727587=1004727587
LCT:1004731187=1004731187
2.
The local time is: 2001.11.2 19:59:48
The Greenich mean time is: 2001.11.2 6:59:48
Local time is sec from Now():1004731188
Local time in sec from TimeValue(...)1004731188
The difference should be zero: 0
GMT:1004727588=1004727588
LCT:1004731188=1004731188
3.
The local time is: 2001.11.2 19:59:49
The Greenich mean time is: 2001.11.2 6:59:49
Local time is sec from Now():1004731189
Local time in sec from TimeValue(...)1004731189
The difference should be zero: 0
GMT:1004727589=1004727589
LCT:1004731189=1004731189
4.
The local time is: 2001.11.2 19:59:50
The Greenich mean time is: 2001.11.2 6:59:50
Local time is sec from Now():1004731190
Local time in sec from TimeValue(...)1004731190
The difference should be zero: 0
GMT:1004727590=1004727590
LCT:1004731190=1004731190
5.
The local time is: 2001.11.2 19:59:51
The Greenich mean time is: 2001.11.2 6:59:51
Local time is sec from Now():1004731191
Local time in sec from TimeValue(...)1004731191
The difference should be zero: 0
GMT:1004727591=1004727591
LCT:1004731191=1004731191
Possible error messages sent to stderr:
2.56. mkdir.bas
To run this test open two terminal windows. Start the program in one until you get the first message. Test in the second window that the directories hoho and hoh/haha were created.
Press enter and after the program has finished check that the directory disappeared.
Example mkdir.bas :
mkdir "./hoho/haha"
print "Now you have dir hoho/haha\n"
print "Press enter..."
line input q
deltree "hoho"
print "Now you do not have dir hoho\n"
Example argpass.bas :
lv = 77
gv = 100
a = 1
b = 2
c = 3
test_sub a,b,c
print "3 a b c>",a," ",b," ",c,"\n"
print "4 lv gv>",lv," ",gv,"\n"
test_sub ByVal a, b, c
print "5 a b c>",a," ",b," ",c,"\n"
sub test_sub(a,b,c)
local lv,d
d = 1
print "1 a b c>",a," ",b," ",c,"\n"
a += 1
b = c + d
lv = 66
gv = 55
print "2 a b c>",a," ",b," ",c,"\n"
end sub
Result executing argpass.bas :
1 a b c>1 2 3
2 a b c>2 4 3
3 a b c>2 4 3
4 lv gv>77 55
1 a b c>2 4 3
2 a b c>3 4 3
5 a b c>2 4 3
Possible error messages sent to stderr:
2.58. callsyntax.bas
This program test that the syntax analyzer checks the parentheses around the CALL subroutine call arguments correct.
This file should compile and run without error producing no output.
Example callsyntax.bas :
end sub
Call test_sub
Call test_sub a
Call test_sub(a)
Call test_sub a,b
Call test_sub(a,b)
Call test_sub (a),b
Call test_sub ((a),b)
Call test_sub (left(a,2))+3
Call test_sub left(a,2)+3
Call test_sub (left(a,2)+3,3)
Call test_sub (i+2)/3 , (j+2)/4
sub test_sub
2.59. reftest1.bas
This sample tests that though the global array is released undef-ing it the local variable a referencing it still has the value. The program should print 1undef.
Example reftest1.bas :
sub test(a)
undef q
print a
end sub
q[1] = 1
test q[1]
print q
Result executing reftest1.bas :
1undef
Possible error messages sent to stderr:
2.60. reftest2.bas
This sample allocates an array as local variable. A global variable referenced by the function argument is set to reference the array. Note that it is not the local variable a is the one that references the array, but rather the global variable that is referenced by a,namely q. If we wanted a to reference the array z then we could use undef a before the ref statement.
When the function returns the array is not released when the local variables are released, because there is a reference to it (variable q) and thje program prints the elements of q.
Example reftest2.bas :
ref a = z
end sub
sub testi(h)
test h
end sub
testi q
for i=1 to 10
print i,". ",q[i],"\n"
next i
sub test(a)
local z,i
for i=1 to 10
z[i] = i
next
Result executing reftest2.bas :
1. 1
2. 2
3. 3
4. 4
5. 5
6. 6
7. 7
8. 8
9. 9
10. 10
Possible error messages sent to stderr:
2.61. reftest3.bas
This sample is the same as `reftest2.bas' with the addition that the function is calling itself recursively ten times. This time when the command ref is issued the argument is a variable referencing reference, referencing ... ten times. Still the effect has to be the same.
Example reftest3.bas :
if s = 1 then
for i=1 to 10
z[i] = i
next
ref a = z
else
test(a,s-1)
endif
end sub
test q,100
for i=1 to 10
print i,". ",q[i],"\n"
next i
sub test(a,s)
local z,i
Result executing reftest3.bas :
1. 1
2. 2
3. 3
4. 4
5. 5
6. 6
7. 7
8. 8
9. 9
10. 10
Possible error messages sent to stderr:
2.62. reftest4.bas
This sample demonstrates the difference between undef a and a = undef.
Example reftest4.bas :
b = 12
ref a = b
ref b = a
' this does not brake the reference, but assigns undef to b (and a)
b = undef
print a," = undef\n"
' Set b to be 12
b = 12
' a becomes the same as b
ref a = b
' b is already the same as a
ref b = a
' b is undefed, but a retains the value
undef b
print a," = 12\n"
undef a
Result executing reftest4.bas :
12 = 12
undef = undef
Possible error messages sent to stderr:
2.63. lettest.bas
This test demonstrates that the assignment copies a whole array recursively, strings, reals, integers, subarrays and even references. When z is changed the last printout has to change also.
Example lettest.bas :
z = "eggdrop"
a[1] = 1
a[2] = 1.1
a[3] = "1111111"
a[4,1] = 4
a[4,2] = 4.4
a[4,3] = "4444444444444444"
ref a[4,4,5,4,5,5,6] = z
b = a
print b[1] ,"\n"
print b[2] ,"\n"
print b[3] ,"\n"
print b[4,1] ,"\n"
print b[4,2] ,"\n"
print b[4,3] ,"\n"
print b[4,4,5,4,5,5,6] ,"\n"
z = "chicken"
print b[4,4,5,4,5,5,6] ,"\n"
Result executing lettest.bas :
1
1.100000
1111111
4
4.400000
4444444444444444
eggdrop
chicken
Possible error messages sent to stderr:
3. CGI Programs
Test programs in this chapter can not be executed in this document, therefore they are only listed here. Some of them can be executed as a CGI process, some specifically require the Eszter SB Application Engine execution environment.
3.1. mt.bas
This is a test program that has to executed in the Eszter SB Application Engine. This is useless being executed from the command line, and in addition being useless result extension specific error, because the CGI module can not handle the execution environment.
Start the Eszter SB Application Engine, configure it so that this program can be executed from some of the configured virtual directories and execute the program.
Note that the Eszter SB Application Engine has both the CGI and the MT modules statically linked so it has to work even if these modules are not installed on the machine.
Example mt.bas :
include cgi.bas
include mt.bas
option cgi$Method cgi::Get or cgi::Upload
cgi::Header 200,"text/html"
cgi::FinishHeader
'-------------------------------------------------------
print """<HTML>
<HEAD>
<title>MT module testing</title>
</HEAD>
<BODY><font face="VERDANA" size="2">
<H1>MT module testing</H1>
"""
'-------------------------------------------------------
MTVar = mt::GetVariable("testvariable")
if not isdefined(MTVar) then MTVar = 1
MTVar = MTVar +1
mt::SetVariable "testvariable",MTVar
print "The variable is: ",MTVar,"""
<p>
"""
call mt::SetSessionId "1"
if not isdefined(mt::GetSessionVariable("a")) then mt::SetSessionVariable "a",13
mt::SetSessionVariable "a" ,mt::GetSessionVariable("a")+1
print "The session variable \"a\" is ",mt::GetSessionVariable("a"),"<p>\n"
mt::DeleteSession "1"
call mt::SetSessionId "2"
if not isdefined(mt::GetSessionVariable("a")) then mt::SetSessionVariable "a",14
mt::SetSessionVariable "a",mt::GetSessionVariable("a")+2
print "The session variable \"a\" is ",mt::GetSessionVariable("a"),"<p>\n"
print "The current directory is ",curdir(),"<p>\n"
print "The new session is:",mt::GetSessionId(),"""
mt:SessionTimeout 20*60,"timeout.bas"
</BODY>
</HTML>
"""
#!/usr/bin/scriba -c
global const nl = "\n"
Const NumberOfCookies = 3
3.2. mtlock.bas
This is a test program that has to executed in the Eszter SB Application Engine. This is useless being executed from the command line, and in addition being useless result extension specific error, because the CGI module can not handle the execution environment.
Start the Eszter SB Application Engine, configure it so that this program can be executed from some of the configured virtual directories and execute the program.
Note that the Eszter SB Application Engine has both the CGI and the MT modules statically linked so it has to work even if these modules are not installed on the machine.
Example mtlock.bas :
'
' Call this program from several browsers and test locking and unlockings
' seeing how the different programs run and return an answer
'
global const nl = "\n"
include cgi.bas
include mt.bas
option cgi$Method cgi::Get or cgi::Upload
cgi::Header 200,"text/html"
cgi::FinishHeader
'-------------------------------------------------------
print """<HTML>
<HEAD>
<title>MT module lock testing</title>
</HEAD>
<BODY><font face="VERDANA" size="2">
<H1>MT module lock testing</H1>
"""
'-------------------------------------------------------
if isdefined(cgi::Param("lockw")) then
mt::LockWrite cgi::Param("lockw")
end if
if isdefined(cgi::Param("lockr")) then
mt::LockRead cgi::Param("lockr")
end if
if isdefined(cgi::Param("unlockw")) then
mt::UnlockWrite cgi::Param("unlockw")
end if
if isdefined(cgi::Param("unlockr")) then
mt::UnlockRead cgi::Param("unlockr")
end if
print """This is OK
</BODY>
</HTML>
"""
#!/usr/bin/scriba -c
Example echo.bas :
include cgi.bas
option cgi$Method cgi::Get or cgi::Upload
' cgi::RequestBasicAuthentication "Test Realm"
cgi::Header 200,"text/html"
'
' We are setting several cookies. The expiry time is ten seconds so you can test that
' the cookies are sent by the browser if you press some of the buttons fast enough,
' but it does not if you are slow
'
for i=1 to NumberOfCookies
' cookie(i) is i, no domain is defined, path is /, expires after 5 seconds, not secure
cgi::SetCookie "cookie" & i,i,undef,"/",gmtime()+10,false
next i
cgi::FinishHeader
'-------------------------------------------------------
print """<HTML>
<HEAD>
<title>CGI parameter testing</title>
</HEAD>
<BODY><font face="VERDANA" size="2">
<H1>View CGI Parameters</H1>
This page shows the cgi parameters the way it was uploaded.
<!-- here is the result of the previous HTTP request -->
<FONT SIZE="3">
<PRE>
CGI system variables
--------------------
"""
'-------------------------------------------------------
print "ServerSoftware = ",cgi::ServerSoftware(), nl
print "ServerName = ",cgi::ServerName(), nl
print "GatewayInterface= ",cgi::GatewayInterface(),nl
print "ServerProtocol = ",cgi::ServerProtocol(), nl
print "ServerPort = ",cgi::ServerPort(), nl
print "RequestMethod = ",cgi::RequestMethod(), nl
print "PathInfo = ",cgi::PathInfo(), nl
print "PathTranslated = ",cgi::PathTranslated(), nl
print "ScriptName = ",cgi::ScriptName(), nl
print "QueryString = ",cgi::QueryString(), nl
print "RemoteHost = ",cgi::RemoteHost(), nl
print "RemoteAddress = ",cgi::RemoteAddress(), nl
print "AuthType = ",cgi::AuthType(), nl
print "RemoteUser = ",cgi::RemoteUser(), nl
print "RemoteIdent = ",cgi::RemoteIdent(), nl
print "ContentType = ",cgi::ContentType(), nl
print "ContentLength = ",cgi::ContentLength(), nl
print "UserAgent = ",cgi::UserAgent(), nl
print "Cookie = ",cgi::RawCookie(), nl
print "Referer = ",cgi::Referer(),nl
print "Password = ",Environ("HTTP_PASSWORD"),nl
print "Full auth string= ",Environ("HTTP_AUTHORIZATION"),nl
print "\nCookies:\n"
for i=1 to NumberOfCookies
print "cookie" & i," ",cgi::Cookie("cookie" & i),"\n"
next i
print "Text field using Param(\"TEXT-FIELD\") is ",cgi::Param("TEXT-FIELD"),nl,nl
if cgi::RequestMethod() = "GET" then
print "GET text field using GetParam(\"TEXT-FIELD\") is ",cgi::GetParam("TEXT-FIELD"),nl
end if
if cgi::RequestMethod() = "POST" then
print "POST text field using PostParam(\"TEXT-FIELD\") is ",cgi::PostParam("TEXT-FIELD"),nl
if cgi::ContentType() like "multipart*" then
print "Original file name is ",cgi::FileName("FILE-UPLOAD-NAME"),nl
if cgi::FileLength("FILE-UPLOAD-NAME") > 0 then
print "File of length ",cgi::FileLength("FILE-UPLOAD-NAME")," bytes is saved\n"
on error goto NoSave
cgi::SaveFile "FILE-UPLOAD-NAME","E:/MyProjects/sb/upload.txt"
else
print "There is no uploaded file."
end if
end if
end if
print """</PRE><TABLE><TR><TD BORDER=0 BGCOLOR="EEEEEE"><PRE>
A simple form to POST parameters:<BR>
<FORM METHOD="POST" ACTION="echo.bas">
<INPUT TYPE="TEXT" VALUE="DEFAULT TEXT" NAME="TEXT-FIELD">
<INPUT TYPE="SUBMIT" NAME="SUBMIT-BUTTON" VALUE=" POST ">
</FORM>
</PRE></TD><TD BORDER=1 width="20"> </TD><TD BORDER=0 BGCOLOR="EEEEEE"><PRE>
A simple form to GET parameters:<BR>
<FORM METHOD="GET" ACTION="echo.bas">
<INPUT TYPE="TEXT" VALUE="DEFAULT TEXT" NAME="TEXT-FIELD">
<INPUT TYPE="SUBMIT" NAME="SUBMIT-BUTTON" VALUE=" GET ">
</FORM>
</PRE></TD></TR></TABLE><PRE>
<hr>
A simple form to UPLOAD a file:<BR>
<FORM METHOD="POST" ACTION="echo.bas" ENCTYPE="multipart/form-data">
<INPUT TYPE="TEXT" VALUE="DEFAULT TEXT" NAME="TEXT-FIELD">
<INPUT TYPE="FILE" VALUE="FILE-UPLOAD-VALUE" NAME="FILE-UPLOAD-NAME">
<INPUT TYPE="SUBMIT" NAME="SUBMIT-BUTTON" VALUE="UPLOAD FILE">
</FORM>
<hr>
</BODY>
</HTML>
"""
stop
NoSave:
print "An error has happened saving the file. Code =",error(),nl
resume next
#!/usr/bin/scriba -c
global const nl = "\n"
Const NumberOfCookies = 3
Example echoquerystring.bas :
#! /usr/bin/scriba -c
include cgi.bas
cgi::Header 200,"text/html"
cgi::FinishHeader
print """<HTML>
<BODY>
<PRE>
"""
print Environ("QUERY_STRING")
print """</PRE>
</BODY>
</HTML>
"""
stop
Example getparam.bas :
#! /usr/bin/scriba -c
include cgi.bas
cgi::Header 200,"text/html"
cgi::FinishHeader
print """<HTML>
<BODY>
<PRE>
"""
print cgi::GetParam("apple")
print """</PRE>
</BODY>
</HTML>
"""
stop
Example listenv.bas :
#! /usr/bin/scriba -c
include cgi.bas
cgi::Header 200,"text/html"
cgi::FinishHeader
print """<HTML>
<BODY>
<PRE>
"""
i = 0
while IsDefined( Environ(i) )
print i," ",Environ(i),"\n"
i = i+1
wend
print """</PRE>
</BODY>
</HTML>
"""
stop
Example mysqlcgi.bas :
option cgi$Method cgi::Get or cgi::Upload
cgi::Header 200,"text/html"
cgi::FinishHeader
print """
<html><body>
Now we start to connect to the MySQL Server
<PRE>
"""
dbh = mysql::Connect("test")
print "The data base handle is: ",dbh,"\n"
' mysql::Shutdown dbh
' print mysql::ErrorMessage(),"\n"
print mysql::Stat(dbh)
print
mysql::query dbh,"delete from users where name='Kakukk'"
print "Affected rows after delete is: ",mysql::AffectedRows(dbh)
print
mysql::query dbh,"insert into users values ('Kakukk',52)"
print "Affected rows after inserting kakukk: ",mysql::AffectedRows(dbh)
print
print "Info is: ",mysql::Info(dbh)
print
mysql::query dbh,"select * from users order by name desc"
print "Affected rows after select: ",mysql::AffectedRows(dbh)
print
' mysql::DataSeek dbh,1
' print
i=0
while mysql::fetcharray(dbh,q)
i=i+1
print i,". ",q[0]," ",q[1]
print
wend
print "Character set name is: ",mysql::CharacterSetName(dbh)
print
mysql::query dbh,"select * from users order by name desc"
print "Affected rows after select: ",mysql::AffectedRows(dbh)
print
' mysql::DataSeek dbh,1
' print
i=0
while mysql::FetchHash(dbh,q)
i=i+1
print i,". "
print
print "name=",q{"name"}
print
print "age=",q{"age"}
print
wend
' mysql::DataSeek dbh,0
on error resume next
mysql::query dbh,"select * from user"
print "Last error is: ",mysql::ErrorMessage(dbh)
print
print "Client info is: ",mysql::GetClientInfo()
print
print "Host info is: ",mysql::GetHostInfo(dbh)
print
print "Proto info is: ",mysql::GetProtoInfo(dbh)
print
print "Server info is: ",mysql::GetServerInfo(dbh)
print
mysql::query dbh,"SHOW PROCESSLIST"
print "Affected rows after show processlistselect: ",mysql::AffectedRows(dbh)
print
i=0
while mysql::fetcharray(dbh,q)
i=i+1
print i,". ",q[0]
' mysql::kill dbh,q[0]
print
wend
print "ping result: ",mysql::Ping(dbh)
print "haho"
print
on error resume next
mysql::Query dbh,"INSERT INTO autoinc values ('huuuh',null)"
print mysql::ErrorMessage(dbh)
print
print mysql::InsertId(dbh)
print
print "Thread id=",mysql::ThreadId(dbh)
print
mysql::kill dbh, mysql::ThreadId(dbh)
mysql::Close(dbh)
print """
</PRE>
</BODY></HTML>
"""
import mysql.bas
import cgi.bas
Example postparam.bas :
#! /usr/bin/scriba -c
include cgi.bas
cgi::Header 200,"text/html"
cgi::FinishHeader
print """<HTML>
<BODY>
<PRE>
<FORM METHOD="POST">
<INPUT TYPE="TEXT" NAME="apple">
</FORM>
"""
print cgi::PostParam("apple")
print """</PRE>
</BODY>
</HTML>
"""
stop
Example 1runrestart.bas :
chdir "\\"
mt::ListSessions SessionArray
for i= lbound(SessionArray) to ubound(SessionArray)
if len(SessionArray[i]) > 3 then
print "Deleting the session ",SessionArray[i],"\n"
mt::DeleteSession SessionArray[i]
end if
next i
sleep 30
import mt.bas
Example cgigetex.bas :
q = undef
cgi::Header 200,"text/html"
cgi::FinishHeader
print """
<HTML>
<HEAD>
<title>GetParamEx test</title>
</HEAD>
<BODY>
<FONT FACE="Verdana" SIZE="2">
<H1>GetParamEx testing</H1>
This is a test that checks the cgi module function GetParamEx. Call this script
using the URL <FONT SIZE="3">
<pre>
/cgi-bin/cgimodtest.bas?a=1&a=2&a=anything
</pre>
</font>
<p>
"""
do
param = cgi::GetParamEx("a",q)
print "Param is ",param," q is ",q,"<p>\n"
loop while IsDefined(param)
print """That is all
</BODY>
</HTML>
"""
import cgi.bas
Example run404.bas :
<HTML>
<BODY>
The real page was not found, howerver<P>
"""
print "Hello, this program runs\n"
for i=1 to 10
print sin(i*pi/10),"\n"
print "<P>\n"
next i
print "</BODY></HTML>\n"
print """HTTP/1.0 200 OK
Content-Type: text/html