THIMK.biz   For users of Internet and Personal Computers.  <contact>


Sample Programs from PowerBASICTM programming guide
Code can be copied from guide (or here), pasted into compiler, and run.
     [A sample subroutine appears on the cover image.]
Say something to screen and disk file:
For starters: copy this into PB compiler, and press ctrl-e
REM hello.bas
FUNCTION PBMAIN
PRINT "hello"
WAITKEY$
hf&=FREEFILE
OPEN "out.txt" FOR OUTPUT AS #hf&
PRINT #hf&, "hello"
CLOSE #hf&
END FUNCTION
See how colored text looks on different backgrounds:
REM ColorTxt.bas by Donald A. Miller, 2002
REM Syntax = COLOR [foreground], [background] [, count]
REM count is optional argument for number of characters to color
FUNCTION PBMAIN
FOR j&=0 TO 15
FOR i&=0 TO 15
COLOR i& , j&
PRINT " ";FORMAT$(i&);",";FORMAT$(j&);" ";
NEXT i& , j&
WAITKEY$
END FUNCTION
Here is a simple program to show that PB can create objects larger than 1.5Gb on a 512Mb-RAM PC, using virtual memory management by 32 bit MS Windows, no disk swapping by program.
REM MakeMbFile.bas to write test file
REM Reference "Power BASIC for Business and Technology"
REM by Donald A. Miller, © 2003; available from http://thimk.biz
REM 1Mb = 1048576 bytes, 1Kb = 1024 bytes
REM For inputs of mb.txt 5, generated files is 5Mb, and import to a robust text editor
REM splits into lines of maximum length 32767, set by Operating System
REM Each written Mb starts with 1 with rest 0's.
FUNCTION PBMAIN
REM Takes input from command line, if not empty, else asks.
v$=COMMAND$
IF 0&<LEN(v$) THEN GOTO skp
PRINT "Makes test data file, given file name and number of Mb, separated by space."
PRINT "On DOS command line, use ";$DQ;"makembfile n";$DQ;" for n Mb,"
PRINT "or ";$DQ;"makembfile n &> mb.log ";$DQ;" to save results in file mb.log."
PRINT "For over-night run, can use batch file of the form mb.bat of lines"
PRINT " makembfile 1000mb.txt 1000 >mblog.txt"
PRINT " makembfile 1500mb.txt 1500 >>mblog.txt"
PRINT " makembfile 2000mb.txt 2000 >>mblog.txt"
PRINT "IF program is started with no right arguments, this description appears,"
PRINT " and user is asked for input, such as: ";$DQ;"1mb.txt 1";$DQ;", or nothing _ to end."
LINE INPUT "What file name and how many Mb wanted? " , v$
skp:
'print v$
n& = PARSECOUNT(v$," ")
'print n&
IF n&<2 THEN
PRINT "Input did not have two arguments. Program ends."
SLEEP 1500
EXIT FUNCTION
END IF
fnm$ = PARSE$(v$," ",1)
n& = VAL(PARSE$(v$," ",2))
'PRINT fnm$,n&
STDOUT "start: "+DATE$+" "+TIME$+"; ";
s1$ = "1"+REPEAT$(1048574,"0")+" "
s2$ = REPEAT$(n&,s1$)
f& = FREEFILE
OPEN fnm$ FOR BINARY AS #f&
PUT$ #f&, s2$
SETEOF #f&
CLOSE #f&
STDOUT "end: "+DATE$+" "+TIME$
SLEEP 1000
END FUNCTION
REM On 1.33GHz Athlon PC, 512 Mb DDR/266 SDRAM, Windows 2000:
' 1Mb took &<1 sec
' 10mb took 6 sec
' 50 Mb took 24 sec,
' 100Mb took 50 sec
' 500Mb took 10 min 39 sec
' 1000Mb took 27 min 13 sec
' 1500Mb took 39 minutes
' 2000Mb stopped with Windows message that virtual memory was low and would be
' increased.
' Not yet tested on larger RAM.


    About the Author , Dr. Donald A. Miller