- PRINT & PRINT USING functions
- LPRINT
- MERGE
- Variables string,integer and real
- Array (dim)
- Labels
- GOTO & GOSUB
- Math functions
- I/O functions
- Insert function
- Data & Reset function
- FOR TO NEXT STEP
- Date$ & Time$
- If <,>,= & else functions
- Complex formula
- Most used string functions
Apache seting:
modify <Directory> in
httpd.conf:
and add at the end those line:
Also, copy "script.aig" in your root
directory.
To call:
http://www.yoursite.com/script.aig?folder\yourscript.bas?param1¶m2¶mx
To receive your parameter:
a$=param$(1)
b$=param$(2)
param$(0) is the script name. expl. yourscript.bas
InsertFilename$:
With this function, you can insert a HTML page
with an access to all your basic variable.
In your HTML: <basic $a> is replaced by the
variable a$ in the code.
One command by line
No binary I/O No database commands
No help
HTML form hard to produce? Not now!
Now you can use FrontPage (2003 recommended) to produce you form( text box,
upload box,etc..) READY to use with Easy Basic, with
NO setup from the source file.
The data from the first TextBox is moved in Param$(1), the data from
the second text box is moved in Param$(2), etc.. The converter
modify your button.
- The Server script
On the server side of the HTTP link,application
serversand
other dynamic content servers such asWeb
content management systems
provide content through a large variety of techniques and
technologies typified by the scripting approach.
-------------------------------------------------------------------------------
Rem This is a comment
: ... separate BASIC statements on one line
_ ... placed at the end of the line to indicated that the statement
continues to the next line.
END ... end the main program (same as STOP in FORTRAN)
label: ... a name followed by a colon
BASIC uses double quotes (") to enclose a string; FORTRAN a single quote (').
-------------------------------------------------------------------------------
Declare Variable Type
Variable Types (type suffix)
variable$ ... character/string of adjustable length
variable ... integer*2
-32,768 -- 32,767 in decimal (default)
i%=&h0 -- i%=&hFFFF in hexadecimal
i%=&o0 -- i%=&o177777 in octal
variable& ... integer*4 (double precision)
-2,147,483,648 -- 2,147,483,647
i&=&h0& -- i&=&hFFFFFFFF& in hexadecimal
(The first "&" is the base; the second "&" is "double precision".)
i&=&o0& -- i&=037777777777& in octal
variable! ... real*4 (default; e.g., x! and x are treated as the same variable,
but a! and a% are not.)
-3.4X10^38 -- 3.4X10^38 (~7 significant figures)
(Note "!" does not mean factorial.
Ok in Excel macro, but not as formula in worksheet cells.)
variable# ... real*8 (double precision)
-1.7X10^308 -- 1.7X10^308 (~15 significant figures)
DEFINT a-z 'INTEGER ... integer (INTEGER*2)
DEFLNG a 'LONG ... double precision integer (INTEGER*4)
DEFSNG a 'SINGLE ... real (REAL*4)
DEFDBL a 'DOUBLE .,. double precision (REAL*8)
DEFSTR a 'STRING ... All variables beginning with "A" are strings,
unless specified otherwise by (%, &, !, or #)
declare variablename AS type ... general format
"declare" is one of the following:
DIM
REDIM
"type" is one of the following:
INTEGER .. 2-byte integer
LONG .. 4-byte integer
SINGLE .. 4-byte real
DOUBLE .. 8-byte real
STRING .. character*(*)
STRING*n .. character*n
ex.
DIM i(100) AS INTEGER
DIM i(1 TO 100, -50 TO 50) AS INTEGER ... negative limits are allowable
DIM a!(100) AS SINGLE
DIM a AS STRING variable length string
DIM a AS STRING*10 fixed length string
DIM a$ AS STRING*10 ... no good (since a$ is a string of adjustable length)
ARRAYS
Array variables do not necessarily have to be declared; compiler gives a warning.
The default lower bound in BASIC is 0.
OPTION BASE 1 ... change the default lower bound to 1 to conform with FORTRAN
The dimension can be read first before DIM statement is issued.
DIM array(10) ... DIMENSION array(10) in FORTRAN
DIM array(10,20)
DIM array (1 TO 10) AS INTEGER
DIM x(1 TO 10), y(1 TO 10, 1 TO 5)
DIM x(n%+1)
DATA 1., 0., 0., 0. ... same as in FORTRAN
FOR I = 1 TO 4 REAL x(4)
READ x!(i) DATA x/1., 0., 0., 0./
NEXT
-------------------------------------------------------------------------------
QBasic Intrinsic Functions
Math Functions ...
ABS
ATN ... ATAN in FORTRAN
COS
EXP
LOG ... base e in VBA, base 10 in Excel formula (LN is base e in Excel formula)
LOG(x)/LOG(10) ... to return log10 in VBA
RND ... Generate a random number <x
SGN returns -1 (negative), 0 (for 0) or 1 (positive)
SIN
SQR ... SQRT in Excel formula & FORTRAN
TAN
Other Functions ...
LEN(variable) ... returns the number of bytes required by a variable
LEN(string expression) ... returns the number of characters in a string
ASC("A") ... returns the ASCII code of "A";
same as FORTRAN: ICHAR('A')
CHR$(64) ... returns the character corresponding to ASCII 64;
same as FORTRAN: CHAR(64)
EOF(1) ... see if eof is reached in file/device #1 (true or false)
LOC(1) ... returns the number of bytes waiting in the input buffer
LOF(1) ... returns the number of bytes remaining in the output buffer
RSET ... right justify a string variable
LSET ... left justify a string variable
ex. LSET NewVariable$ = oldvariable$
LTRIM$ ... strip away leading spaces
ex. FOR i=1 to 5 ... produce x(1) = ???
i$ = LTRIM$(STR$(i)) x(2) = ???
PRINT "x("; i$; ") = "; :
INPUT "", x(i)
NEXT i
ex. FOR i=1 to 5 ... produce x(1) = ???
PRINT " a("; LTRIM$(STR$(i)); ")="; a(i)
NEXT i
RTRIM$ ... strip away trailing spaces
good for comparing fixed length and variable length strings
ex. IF RTRIM$(fixed$) = variable$ THEN ...
INSTR(string1$, string2$)
... returns the position in string1 where string2 is found
0 means no match
ex. string1$ = "hi, class"
string2$ = "class"
PRINT INSTR(string1$, string2) ... gives 5
INSTR(start_position%, string1$, string2$)
... returns the position in string1 where string2 is found
start searching for matching at start_position%
good for searching for multiple matching
LEFT$(string$, n%) ... return the leftmost n% characters from string$
ex. PRINT LEFT$("hi, class", 4) ... gives "hi, "
RIGHT$(string$, n%) ... return the rightmost n% characters from string$
ex. PRINT RIGHT$("hi, class", 4) ... gives "lass"
MID$(string$, start%, n%)
... return n characters from string$, starting at start
ex. PRINT MID$("hi, class", 5, 2) ... gives "cl"
MID$("hi, class", 1) = "H" ... replace the 1st character with "H"
gives "Hi, class"
MID$("hi, class", 2) = "Go" ... gives "Go, class"
STRING$(n, string$) ... generate string$ n% times
ex. PRINT STRING$(20, "*")
STRING$(n, code%) ... generate string$ n% times
ex. PRINT STRING$(20, 64)
SPACES$(n%) ... generate n% blank spaces
LCASE$(string$) ... convert to lower case; good for case insensitive comparison
UCASE$(string$) ... convert to upper case; good for case insensitive comparison
ex. DO
resp$ = INPUT$(1)
LOOP WHILE UCASE$(resp$) = "Y"
MKI$ ... convert an integer to string
ex. New$ = MKI$(i)
MKS$ ... convert a real variable to string
ex. New$ = MKS$(x!)
STR$ ... convert to string
ex. a$ = STR$(45) ... gives "45"
a$ = STR$(i%)
VAL("45") ... gives 45 (an integer)
ex. i% = VAL("45")
i% = VAL(string$)
r! = VAL("1.2")
ex. trick to ensure that the type is correct
INPUT "enter n: ", n$ | n%=VAL(n$)
------------------------------------------------------------------------------
Concatenation
A$ = "hi,"
B$ = " class"
C$ = A$ + B$ --> gives "hi, class"
C$ = C$ + A$ --> Add one character at a time
Integer division
7/3 --> 2.33333
7\3 --> 2
9.6\2.4 --> 5 (i.e., 10\2 because real numbers are round off before
operation is performed.)
Not very accurate (bugs?) 0.5\1 --> 0
but 1.5\1 --> 2
2.5\1 --> 2
3.5\1 --> 4
(Use int(x+0.5) to round off instead.)
7 MOD 3 --> 1
Precedence of Operations
same as FORTRAN
^ ... exponentiation; same as FORTRAN **
-x^2 means -(x^2) in VBA, but (-x)^2 in Excel formula!!
Assignment
same as FORTRAN
Logical Operators -- Boolean expression, condition
= ... .EQ. in FORTRAN
<> ... .NE.
> ... .GT.
< ... .LT.
>= ... .GE.
<= ... .LE.
0 ... .FALSE.
-1 ... .TRUE.
AND
OR
NOT()
e.g. false = 0000000000000000 (an integer value of 0)
true = 1111111111111111 (an integer value of -1); true=1 in Excel worksheet!
true = or any nonzero value in condition testing, e.g.,
"if 1 then" or "if -1 then"
Variable type is the same as integer.
PRINT 1=1 ... gives -1
e.g., The following is very strange (in QBasic)!
TRUE = 1 FALSE=0
FALSE = NOT(TRUE) ... gives -2, not 0 TRUE = NOT (FALSE) ... gives ?
... gives 0 in VBA
ex. CONST FALSE = 0, TRUE = NOT FALSE ... good for readability or
imitating FORTRAN
... not valid in VBA
ex. Two strings can be compared based on ASCII values ... good for sorting
------------------------------------------------------------------------------
-------------------------------------------------------------------------------
CONDITION, FLOW CONTROL
ELSEIF and ELSE part are optional
IF condition1 THEN -+ ... same as FORTRAN: + IF (condition1) THEN
statement1 | | statement1
ELSEIF condition2 THEN | | ELSEIF (condition2) THEN
statement2 | | statement2
ELSEIF condition3 THEN | | ELSEIF (condition3) THEN
statement3 | | statement3
ELSE | | ELSE
statement4 | | statement4
END IF -+ + END IF
------------------------------------------------------------------------------
ON i GOSUB 10, 20, 30, 40, 50
... goto 10 if i=1, goto 20 if i=2, goto 30 if i=3 etc
... same as FORTRAN: GOTO (10, 20, 30, 40, 50) I
... unstructured; avoid
------------------------------------------------------------------------------
FOR i=1 TO 5 + ... same as FORTRAN: + DO label icount=1, 5
statements | | statements
NEXT count + + label CONTINUE
... The count variable may start with a negative integer.
... STEP other than 1 can be given.
... Infinite loop when STEP 0 is used. (This is not allowed in FORTRAN.)
FOR i=5 TO 1 STEP -1 + ... same as FORTRAN: + DO label icount=5, 1, -1
statements | | statements
NEXT count + + label CONTINUE
Forced exist from FOR ... NEXT loop
FOR i=5 TO 1 STEP -1 + ... same as FORTRAN: + DO label icount=5, 1, -1
statements | | statements
EXIT FOR | | if( ... ) goto 101
statements | | statements
NEXT count + + label CONTINUE
101 outside the loop
Counter is optional ...
ex. FOR count=1 TO 5
statements
NEXT
Nesting ...
ex. FOR i=1 TO 5
FOR j=1 TO 10
statements
NEXT
NEXT
ex. FOR i=1 TO 5
FOR j=1 TO 10
statements
NEXT j
NEXT i
ex. FOR i=1 TO 5
FOR j=1 TO 10
statements
NEXT j, i (list the most inner counter first)
------------------------------------------------------------------------------
WHILE condition label IF (condition) THEN
statements statements
WEND ENDIF
GOTO label
------------------------------------------------------------------------------
Use EXIT DO within IF placed inside the loop to get out of the DO...LOOP
DO +
statements | infinite loop
IF .. THEN EXIT DO |
statements |
LOOP +
Test the condition first (thus, the statements in the loop may be completely skipped.)
DO WHILE condition + ... same as FORTRAN: + label IF (condition) THEN
statements | | statements
LOOP + | END IF
+ GOTO label
DO UNTIL condition + ... same as FORTRAN: + label IF (.not. condition) THEN
statements | | statements
LOOP + | END IF
+ GOTO label
Test the condition afterwards (thus, the statements in the loop are executed
at least once.)
DO +... same as FORTRAN: + label statements
statements | + IF (condition )GOTO label
LOOP WHILE condition+
DO +... same as FORTRAN: + label statements
statements | + IF (.not. condition)GOTO label
LOOP UNTIL condition+
------------------------------------------------------------------------------
INPUT/OUTPUT, FILES
PRINT (in QBasic, not VBA!)
PRINT A; B -- the 2nd item is separated from the 1st by a space.
(May show 2 spaces between numbers because there is also a
space before the positive number.)
PRINT A, B -- the 2nd item is printed at the next tab position
(multiples of 14).
PRINT "A"; B --- the 2nd item is separated from the 1st string by 0 space.
(May show 1 space between the string and the number because
there is a space before the positive number.)
PRINT A; + combine output of several PRINT statements on the same line.
PRINT B +
PRINT A, + combine output of several PRINT statements on the same line.
PRINT B +
PRINT ... no argument ... print a blank line
PRINT "character strings"
PRINT logical expression PRINT USING "###.###"; A ... 123.456 same as F7.3
PRINT USING "$$###.##"; A ... $123.45 (note two $ signs so that the $ sign is next to the number)
PRINT USING "#.###^^^^"; A ... 0.123E+03 same as E9.3
PRINT USING "+###"; A ... +123
PRINT USING "##_! = factorial of ## = ##,###.##"; 10; 10; 123.44 ("_!" gives "!")
... 10! = factorial of 10 = 123.44
fmt$ = "##_! = factorial of ## = ##,###.##" + same as the last line
PRINT USING fmt$; 10; 10; 123.44 +
PRINT "x("; i$; ") = "; using "##.#####^^^^"; x(i)
PRINT using "##.#####^^^^"; a, b, c ... repeat the same format
PRINT "a"; SPC(10); "b" ... skip 10 spaces between "a" and "b"
PRINT "a"; TAB(10); "b" ... print "b" on column 10
LPRINT print data in DOS format (<BR> is replaced by a linefeed(#13+#10))
Other Output Statements
INPUT# 1, variable1
OPEN "filename" FOR OUPUT AS 1 ... same as open(1,file='filename',status='new')
(existing file will be written over -- Be careful!)
OPEN "filename" FOR APPEND AS 1 ... append existing file
OPEN "filename" FOR INPUT AS 1 ... same as open(1,file='filename',status='old')
OPEN "filename" FOR RANDOM AS 1 ... random acess file
OPEN "filename" FOR BINARY AS 1 ... binary file
CLOSE 1 ... same as FORTRAN close(1)
KILL filespec ... same as DOS' "del filespec"
NAME filename1 AS filename2 ... same as DOS' "rename filename1 filename2"
ex. Automatically find the next file number with FREEFILE function
OPEN "file1" FOR INPUT AS 1
n% = FREEFILE
OPEN "file2" FOR INPUT AS n%
INPUT# 1, variable list
WRITE# 1, variable list ... string variables enclosed in " ",
and field separated by "," in the file
PRINT# 1, variable list ... the same as what one will see on screen
try to use WRITE/INPUT combinations
There is no easy way to write '"'. Do the following
q$ = CHR$(34)
PRINT q$; a$; q$
MERGE fn$ Merge a basic script (.bas)
Steps in using a random acess file
1. Define a new type, i.e., new record structure
TYPE newtype
variable1 AS INTEGER
variable2 AS STRING*30
variable3 AS SINGLE
END TYPE
2. Declare a variable of new type
DIM RecordVariable AS newtype
2. Define the length of each field in a file
FIELD #1, 2 AS variable1, 30 AS variable2, 4 AS variable3
3. Open a file
OPEN "filename" FOR RANDOM AS 1 LEN = LEN(RecordVariable)
or
OPEN "filename" FOR RANDOM AS 1 LEN = 36
... calculate the record length by hand
record% = LOF(1) \ LEN(RecordVariable)
... find the number of record in the file
4. Read from or write to file
GET 1, record%, RecordVariable
GET 1, , RecordVariable ... move to the next record
PUT 1, record%+1, RecordVariable
PUT 1, , RecordVariable ... move to the next record
5. Each field in the record variable can be accessed individually
a% = RecordVariable.variable1
a$ = RecordVariable.variable2
a! = RecordVariable.variable3
6. Close file
CLOSE 1
A Binary I/O file
OPEN "filename" FOR BINARY AS #1
The following are the only ways to input from and output to a binary file.
INPUT$
GET 1, position%, RecordVariable
GET 1, , RecordVariable ... move to the next record
PUT 1, position%+1, RecordVariable
PUT 1, , RecordVariable ... move to the next record
SEEK 1, position%
i% = SEEK(1) ... returns position of next read/write
i% = LOC(1) ... returns position of last read/write
DOWNLOAD URL$, FileName$ Download a file FROM Internet TO your script folder
Other functions
Using$(Format, Value) expl.: a$=Using$("###.##",d!)
DOWNLOAD(URL$,FileName$) Download a file FROM Internet TO your script folder
Exp: DOWNLOAD("http://www.aiglonsoft.com/index.html","index.htm") return TRUE or FLASE
Time$ Give the time now
Date$ Give the date of the day
EOD End of Data Flag (for read)
-----------------------------------------------------------------------------