Examples from the NS BASIC Manual


This file contains the example programs used in the Handbook.

These examples follow the commands in alphabetical order. Each statement and function has an example. Please feel free to cut and paste this code into your Newton to try it out!






10 REM Future Value of an Investment
20 PRINT "Enter starting principal"
30 INPUT principal
40 PRINT "Enter interest rate as % (i.e. 10)"
50 INPUT rate
60 PRINT "Enter term (i.e. 12 for monthly)"
70 INPUT term
80 PRINT "Enter number of years"
90 INPUT years
100 REM Compute final interest
110 rate = rate * 0.01 / term
120 balance = principal
130 FOR y = 1 TO years
140 FOR c = 1 TO term
150 interest = rate * balance
160 balance = balance + interest
170 NEXT c
180 NEXT y
185 PRINT "Using our calculations:"
190 PRINT "After ";years;" years the balance is: ";balance
200 REM The easy and fast way
210 PRINT "Using the COMPOUND function:"
215 PRINT compound(rate, years*term) * principal
220 END

10 REM MAKEPACKAGE Example
20 PRINT "Enter starting principal"
30 INPUT principal
40 PRINT "Enter interest rate as % (i.e. 10)"
50 INPUT rate
60 PRINT "Enter term (i.e. 12 for monthly)"
70 INPUT term
80 PRINT "Enter number of years"
90 INPUT years
100 REM Compute final interest
110 rate = rate * 0.01 / term
120 PRINT "After ";years;" years the balance is: "; compound(rate, years*term) * principal
130 END

10 REM ABS Example
20 REM This program returns the positive value of any number INPUT to it.
30 PRINT "Please enter any number:"
40 INPUT Number
50 PRINT "The absolute value of the number you entered is = " ; ABS(Number)

10 REM ADDARRAYSLOT Example
20 a := [1,2,3]
30 PRINT "Please enter any number:"
40 INPUT Number
50 ADDARRAYSLOT(a, Number)
60 PRINT "The new array is = " ; a

10 REM ANNUITY Example
20 REM Compute annuity on monthly basis.
30 PRINT "Annual Interest Rate:"
40 INPUT Rate
50 PRINT "Number of months:"
60 INPUT NumMonths
70 PRINT "Cost of the item:"
80 INPUT Cost
90 PRINT "The cost for all payments is $"; ANNUITY((Rate * 0.01)/12, NumMonths) * Cost

10 REM ARRAYREMOVECOUNT Example
20 a := [1,2,3,4,5,6,7]
30 ARRAYREMOVECOUNT (a, 2,3)
40 PRINT "The new array is = " ; a

10 REM ARRAYTOPOINTS Example
20 shapeArray:=[9,4,25,10,10,40,40,40,25,10]
30 points := ARRAYTOPOINTS(shapeArray)
40 shape := MAKESHAPE(points)
50 wspec := {viewBounds: Â
SETBOUNDS(10, 10, 200, 200)}
60 WINDOW w1, wspec
70 SHOW w1
80 WDRAW w1, shape

5 REM BEEP Example
10 FOR i = 0 TO 13
20 BEEP i
30 WAIT 1
40 NEXT i

5 REM BEGINSWITH Example
10 target := "YES or NO"
20 IF BEGINSWITH(target,"yes") THEN Â
PRINT "It starts with yes"
30 IF BEGINSWITH(target,"YES OR") THEN Â
PRINT "It starts with YES OR"
40 IF BEGINSWITH(target,"No OR") THEN Â
PRINT "It starts with No OR"

10 REM BYE Example
20 PRINT "Quitting NS BASIC"
30 BYE

10 REM CEILING Example
20 PRINT "Please enter a number:"
30 INPUT Number
40 PRINT "Next largest integer is..." ; Â
CEILING(Number)

REM Chain example programs
10 REM Program1
20 PRINT "This is Program 1"
30 CHAIN "Program2"
40 PRINT "Return to Program1"

10 REM Program2
20 PRINT "This is Program 2"
30 CHAIN "Program1",40

10 REM CHR Example
20 REM This demo asks the user for a number Â
and then displays the ASCII character Â
equivalent of it.
30 PRINT "Please enter a number between 1 and 256"
40 INPUT Number
50 PRINT "The Character Equivalent of " ; Â
Number ; " is " ; CHR(Number)

10 REM CLASSOF Example
20 a = 5
30 PRINT CLASSOF(a)
40 a = "Hello"
50 PRINT CLASSOF(a)

10 REM CLOSE Example
20 CREATE chan, "EXAMPLEFile", keyname
30 CLOSE chan

10 REM Clear Screen Example
20 CLS

10 REM COMPOUND Example. This example assumes that interest is being calculated monthly.
20 PRINT "Please enter the Interest rate per year:"
30 INPUT Rate
40 PRINT "Please enter the number of months you wish interest to be calculated for:"
50 INPUT Period
60 PRINT "The percentage gain is " ; COMPOUND((Rate*0.01/12), Period)* 100 ; "%"

10 REM CON Example
20 PRINT "Before Stop"
30 STOP
40 PRINT "After Stop"

10 REM COS Example
20 PRINT "Please enter an angle:"
30 INPUT Angle
40 PRINT "The Cosine of the angle is = ";Â
COS(Angle)

10 REM CREATE Example
20 REM Creates a file...prompts for some information, stores then deletes it.
40 CREATE chan, "EXAMPLEFile", keyname
45 IF FSTAT=1 THEN STOP // CREATE error
50 PRINT "Please enter some key data..."
60 INPUT FileKey
70 fileRecord = {}
80 fileRecord.keyname = FileKey // key
90 PUT chan, fileRecord
100 IF FSTAT=1 THEN STOP // PUT error
110 PRINT "Data now in file is..."
120 GET chan,FetchedData,FileKey
130 IF FSTAT=1 THEN STOP // GET error
140 PRINT FetchedData
150 PRINT "Deleting Record From File"
160 DEL chan,FetchedData

10 REM DATA Example
20 DIM a[10]
30 DATA 4,5,6.5, "This", "Is"
40 DATA "String", "Data", -0.01
50 DATA "1\n2"
60 FOR i = 0 TO 7
70 READ a[i]
80 PRINT a[i]
90 NEXT i
100 READ aString
110 PRINT "1\\n2 the same? "; Â
STREQUAL(aString, "1\n2")

10 REM DATENTIME Example
20 CurTime = TIME()
30 PRINT DATENTIME(CurTime)

10 REM DEL Example
20 REM Creates a file...prompts for some information, stores then deletes it.
40 CREATE chan, "EXAMPLEFile", keyname
45 IF FSTAT=1 THEN STOP // CREATE error
50 PRINT "Please enter some key data..."
60 INPUT FileKey
70 fileRecord = {}
80 fileRecord.keyname = FileKey
90 PUT chan, fileRecord
100 IF FSTAT=1 THEN STOP // PUT error
110 PRINT "Data now in file is..."
120 GET chan,FetchedData,FileKey
130 IF FSTAT=1 THEN STOP // GET error
140 PRINT FetchedData
150 PRINT "Deleting Record From File"
160 DEL chan,FetchedData

10 REM DELETE Example
20 CREATE chan, "Somefile", key
30 DELETE Somefile

10 REM Array Example
20 DIM Names[3]
30 Names[0] = "Peter"
40 Names[1] = "Paul"
50 Names[2] = "Mary"
60 PRINT "Contents of the Names Array:"
70 FOR i = 0 TO 2
80 PRINT Names[i]
90 NEXT i

10 REM DIV Example
20 REM This program takes two numbers and computes number of times the 2 numbers can be divided.
30 PRINT "Please enter two numbers."
40 INPUT Number1,Number2
50 Result = Number1 DIV Number2
60 PRINT "The number of times " ; Number1 ; " can be divided by " ; Number2; " is " ; Result

10 REM DO Example
20 i = 0
30 DO WHILE i < 10
40   i = i + 1
50   IF i > 5 THEN EXIT DO
60 LOOP
70 PRINT i

10 REM PICTUREBUTTON Example
20 shape=[MAKERECT(1,1,30,30), Â
MAKETEXT("I", 12,10,21,21)]
30 myIcon:=MAKEBITMAP(32,32,NIL)
40 DRAWINTOBITMAP(shape, NIL, myIcon)
50 w1Spec = {icon: myIcon, GOTO: 'buttonTap,Â
viewBounds: SETBOUNDS(101, 101, 132, 132)}
60 WINDOW w1, w1Spec, "PICTUREBUTTON"
70 SHOW w1
80 WAIT -1
200 buttonTap: REM Button Tapped
210 HIDE
220 PRINT "Tapped."

10 REM Elements Example
20 X := {a: 1, d: 4, b: 2, c:3}
30 Y := ELEMENTS(X)
40 FOR i=0 TO LENGTH(Y)-1
50 PRINT Y[i]; x.(INTERN(Y[i]))
60 NEXT I

10 REM Block IF Example
20 a = 5
30 b = 10
40 IF a=b THEN
50   PRINT a, b
60   PRINT "The numbers are equal."
70 ELSE
80   PRINT ABS(b-a)
90   PRINT "The numbers are this far apart"
100 END IF

10 REM END Example
20 PRINT "Line Number 1"
30 END
40 PRINT "Line Number 2"

REM ENTER Examples
10 REM Simple Program
20 PRINT "Line 1"

10 REM Second Program
20 PRINT "Line 3"
30 PRINT "Line 4"

10 REM ERASE Example
20 ERASE 30, 40
30 PRINT "Line 30"
40 PRINT "Line 40"
50 PRINT "Line 50"

10 REM EXP Example
20 PRINT "Please enter a number"
30 INPUT Number
40 PRINT "The Natural exponential is " ; EXP(Number)

10 REM FLOOR Example
20 PRINT "Please enter a number"
30 INPUT Number
40 PRINT "Next Smallest integer is..." ; FLOOR(Number)

10 REM FOR Loop Example
20 FOR i = 1 TO 10 STEP 3
30   FOR j = 1 to 2
40     PRINT i,j
50   NEXT j
60 NEXT i

10 REM FUNCTION Example
20 DEF FNS(starttime)=(TICKS()-starttime)/60
30 FUNCTION tot(b) BEGIN LOCAL x:=0; FOR i:=0 TO LENGTH(b)-1 DO x:=x+b[i]; x END
40 iterations=1000
50 a=ARRAY(iterations, 25)
60 GOSUB 90 //sum using NS BASIC loop
70 GOSUB 170 //sum using function
80 STOP
90 REM sum using NS BASIC loop
100 tm=TICKS()
110 x=0
120 FOR i=0 TO LENGTH(a)-1
130 x=x+a[i]
140 NEXT i
150 PRINT "Method 1:", U:fns(tm)
160 RETURN
170 REM sum using function
180 tm=TICKS()
190 x=U:tot(a)
200 PRINT "Method 2:", U:fns(tm)
210 RETURN

10 REM GET Example
20 PRINT "The first 5 first names of the names file will be displayed."
30 OPEN CH,"Names"
40 IF FSTAT <> 0 THEN STOP
50 FOR i = 1 TO 5
60 GET CH, NameData
70 IF FSTAT = 1 THEN STOP
80 PRINT NameData.Name.first
90 NEXT i

10 REM GETGLOBALS Example. Show User's name and address
20 PRINT GETGLOBALS().userConfiguration.company
30 PRINT GETGLOBALS().userConfiguration.address
40 PRINT GETGLOBALS().userConfiguration.cityzip

10 REM GOSUB Example
20 PRINT "GOSUB Routines-"
30 GOSUB 70 //Routine #2
40 GOSUB routine3
50 PRINT "Routine #1"
60 END
70 REM Routine #2
80 PRINT "Routine #2"
90 RETURN
110 routine3: REM
120 PRINT "Routine #3"
130 RETURN

10  REM GOTO Example
20  PRINT "Please enter a number..."
30  REM input a number
40  INPUT x
50  IF x >100 THEN GOTO bigger
60  PRINT "The number is too small"
70  PRINT "Please Re-enter..."
80  GOTO 0030 //input a number
90 bigger: END

10 REM HASSLOT Example
20 testFrame := {name: "Fred", fridge: TRUE}
30 IF hasslot(testFrame, 'name) THEN Â
PRINT "It has a name"
40 IF HASSLOT(testFrame, 'size) THEN Â
PRINT "It has a size"
50 IF HASSLOT(testFrame, 'fridge) THEN Â
PRINT "It has a fridge"

10 REM HEXDUMP Example
20 dumpString = "This is a String"
30 PRINT HEXDUMP(dumpString,0,20)

10 REM HIDE Example
20 W1Spec := {ViewBounds: Â
SETBOUNDS(10, 50, 100, 100)}
30 W2Spec := {ViewBounds: Â
SETBOUNDS(20, 70, 100, 100)}
40 WINDOW Win1, W1Spec
50 WINDOW Win2, W2Spec
60 WPRINT Win1, "Window 1"
70 WPRINT Win2, "Window 2"
80 SHOW [Win1, Win2]
90 WAIT
100 HIDE Win2
110 SHOW Win2
120 HIDE

10 REM HITSHAPE Example
15 button = MAKEOVAL(10,10,40,40)
20 ws := {GOTO: 'ovalHit, DRAWING: button}
30 WINDOW w1,ws
50 SHOW w1
60 WAIT -1
100 ovalHit: REM process user tap
110 IF HITSHAPE(button, ws.firstX, ws.firstY) THEN PRINT "You tapped in the button!" ELSE PRINT "You missed the button!"
120 HIDE

10 REM HOURMINUTE Example
20 CurTime = TIME()
30 PRINT HOURMINUTE(CurTime)

10 REM HWINPUT Example
15 PopUp = ["Ford", "Arthur", "Trillian", "Zaphod"]
20 HWINPUT Name,"Please enter your Name...",PopUp
30 PRINT "Hello " ; Name

10 REM IF THEN ELSE Example
20 PRINT "Please Enter a Number."
30 INPUT Number
40 IF Number>=100 THEN PRINT "Number is greater than or equal to 100" ELSE PRINT "Number is less than 100"
50 IF Number=0 THEN PRINT "Number is equal to zero"

10 REM INPUT Example
20 PRINT "Please enter two things."
30 INPUT a,b
40 PRINT "Please enter one more thing."
50 INPUT c$
60 PRINT "You typed in...", a; " & "; b; " & "; c$

10 REM INTERN Example
20 frame:={a: 1, b:2, c:3}
30 frame_ele=INTERN("b")
40 PRINT frame.(frame_ele)
50 frame_names=ELEMENTS(frame)
60 FOR i=0 TO LENGTH(frame_names)-1
70 PRINT frame_names[i], frame.(INTERN(frame_names[i]))
80 NEXT i 
90 PRINT frame

10 REM LENGTH Example
20 a := [1,2,"Three", 4]
30 PRINT "a has "; LENGTH(a); " elements."

10 REM LET Example
20 PRINT "What is your Name?"
30 INPUT Name$
40 PRINT "What is your age?"
50 INPUT age
60 LET age = age + 10
70 PRINT Name$; "...";"In 10 years your age will be...";age

0010 REM Counting Program
0020 FOR i = 1 TO 10
0030   PRINT i
0040 NEXT i
0050 PRINT "All Done"

10 REM LOG Example
20 PRINT "Please enter a number"
30 INPUT Number
40 PRINT "The LOG of the number entered is "; LOG(Number)

10 REM LOOP Example
20 i = 0
30 DO
40   i = i + 1
50   IF i > 5 THEN EXIT DO
60 LOOP WHILE i < 10
70 PRINT i

10 REM WDRAW Example
20 W1Spec={viewBounds: SETBOUNDS(10, 10, 150, 75)}
30 WINDOW WinNum, W1Spec
40 SHOW WinNum
50 WDRAW WinNum, [MAKELINE(55,15,75,45), MAKEOVAL(10,10,40,40)], {penSize:2, penPattern:vfGray, fillPattern:vfBlack}

10 REM MAKEPACKAGE Example
20 PRINT "Enter starting principal"
30 INPUT principal
40 PRINT "Enter interest rate as % (i.e. 10)"
50 INPUT rate
60 PRINT "Enter term (i.e. 12 for monthly)"
70 INPUT term
80 PRINT "Enter number of years"
90 INPUT years
100 REM Compute final interest
110 rate = rate * 0.01 / term
120 PRINT "After ";years;" years the balance is: "; compound(rate, years*term) * principal
130 END

10 REM MAX Example
20 PRINT "Please enter a number"
30 INPUT Number1
40 PRINT "Please enter a second number"
50 INPUT Number2
60 PRINT "The largest number entered was " ; MAX(Number1,Number2)

10 REM MIN Example
20 PRINT "Please enter a number"
30 INPUT Number1
40 PRINT "Please enter a second number"
50 INPUT Number2
60 PRINT "The smallest number entered was " ; MIN(Number1,Number2)

10 REM MOD Example
20 REM This program takes two numbers and computes their modulus.
30 PRINT "Please enter two numbers."
40 INPUT Number1,Number2
50 Result = Number1 MOD Number2
60 PRINT "The modulus of " ; Number1 ; " and " ; Number2; " is " ; Result

10 REM NEW Example
20 PRINT "Hello World!"

0010  REM program template
0020  LET appSpec={goto:'endProgram,title: "Demo"}
0030  window app,appSpec,"APP"
0040  show app
0050  widgetdef Layout_0
0060  window wlist,Layout_0
0070  show wlist
0100  wait -1 // indefinitely
9000 endProgram: rem
9010  hide
9020  stop

10 REM FOR/NEXT Example
20 FOR i = 1 TO 5
30 PRINT i
40 NEXT i

10 REM NOTIFY Example
20 NOTIFY("Demo Program","There has been an unexpected error")
30 END

10 REM NUMBERSTR Example
20 Number = 127.924
30 PRINT "Number is " ; Number
40 PRINT "String representation is "; NUMBERSTR(Number)

10 REM Error Checking Example
20 ON ERROR GOTO 60
30 x = 1+"2"
40 ON ERROR GOTO 0
50 END
60 PRINT "Error Routine"

10 REM ON GOSUB/GOTO Example
20 PRINT "Please enter a value for expression..."
30 INPUT Expression
40 ON Expression GOTO 50, middle, 90
50 PRINT "Routine #1"
60 END
70 middle: PRINT "Routine #2"
80 END
90 PRINT "Routine #3"

10 REM OPEN file Example
20 OPEN CH,"Names"
30 IF FSTAT <> 0 THEN STOP
40 GET CH,NAMEDATA
50 PRINT NAMEDATA.Name.last

10 REM ORD Example
20 PRINT "Please enter a string"
30 INPUT X
60 PRINT "The ORD of the first character of X is ";ORD(X[0])

10 REM POINTSTOARRAY Example
20 dSpec := {viewBounds: SETBOUNDS(1, 1, 239,Â
318), viewFlags: VSHAPESALLOWED + VCLICKABLEÂ
+ VGESTURESALLOWED}
30 WINDOW drawWin, dSpec, "DRAW"
40 spec := {GOTO: 'closeApp}
50 WINDOW quitWin, spec, "LARGECLOSEBOX"
60 SHOW drawWin, quitWin
70 WAIT -1
90 closeApp: REM User Tapped Close Box
100 IF LENGTH(dSpec.windowSpec.viewChildren)Â
< 1 THEN GOTO noKids
110 PRINT "First Drawing: "; POINTSTOARRAYÂ
(drawSpec.windowSpec.viewChildren[0].points)
120 noKids: HIDE
130 END

10 REM POW Example
20 PRINT "Please enter a number"
30 INPUT X
40 PRINT "Please enter power to raise to"
50 INPUT Y
60 PRINT "X to the power Y is ";POW(X,Y)

10  REM PROGRESS Example
20  upperMessage := " Progress example"
30  FOR i= 1 TO 100 STEP 10
40    IF i < 10 THEN Â
         lowerMessage := "Warming UpÉ"
50    IF i > 10 AND i <= 50 THEN Â
         lowerMessage := "RunningÉ"
60    IF i >= 50 and i < 80 THEN Â
         lowerMessage := "Finishing UpÉ"
70    IF i >= 80 THEN Â
         lowerMessage := "Shutting DownÉ"
80    PROGRESS(upperMessage, lowerMessage, i)
90    WAIT 250
100  NEXT i
110  PROGRESS(NIL,NIL,NIL)

10 REM PRINT Example
20 PRINT "The PRINT Command"
30 PRINT
40 ; "Can be used to separate", "text"
50 ; "Or Join Numbers and Text"
60 PRINT 10*10; " Llamas"

10 REM PUT Example
20 REM Creates a file...prompts for some information, stores then deletes it.
40 CREATE chan, "EXAMPLEFile", keyname
45 IF FSTAT=1 THEN STOP // CREATE error
50 PRINT "Please enter some key data..."
60 INPUT FileKey
70 fileRecord = {}
80 fileRecord.keyname = FileKey
90 PUT chan, fileRecord
100 IF FSTAT=1 THEN STOP // PUT error
110 PRINT "Data now in file is..."
120 GET chan,FetchedData,FileKey
130 IF FSTAT=1 THEN STOP // GET error
140 PRINT FetchedData
150 PRINT "Deleting Record From File"
160 DEL chan,FetchedData

10 REM RANDOM Example
20 REM Displays 10 random numbers between 5 and 15
30 FOR i = 1 to 10
40 PRINT RANDOM(5,15)
50 NEXT i

10 REM RANDOMIZE Example
20 RANDOMIZE 34
30 FOR i = 1 to 10
40 PRINT RANDOM(1,10)
50 NEXT i

10 REM READ Example
20 DATA 0.76,3.55,7.80,2.65,9.52
25 DATA 9.96,6.32,8.15,6.61,9.73
30 FOR i = 1 TO 10 
40 READ a
50 PRINT a
60 NEXT i

10 REM REM Example 1
15 A=1 // Set A to 1
20 PRINT "This line is printed"
30 REM But this line is not printed
40 REM Neither is this one

10 REM REM Example 2
20 REM It shows how the REM Statement is used with
30 REM GOSUB and GOTO Routines.
40 GOSUB 70
50 PRINT "Return from GOSUB"
60 END
70 REM Notice the Backslashes
80 PRINT "Here I Am!"
90 RETURN

10 REM REMAINDER Example
20 REM This program takes two numbers and computes the remainders of their division.
30 PRINT "Please enter two numbers."
40 INPUT Number1,Number2
50 PRINT "The Remainder of " ; Number1 ; " divided by " ; Number2; " is " ; REMAINDER(Number1, Number2)

10 REM REMOVESLOT Example
20 aFrame = {name: "Fred", fridge: NIL}
30 REMOVEslot(aFrame, 'fridge)
40 PRINT aFrame

10 REM RENUM Program
20 PRINT "This is line 0020"
30 PRINT "This is line 0030"
40 PRINT "This is line 0040"
50 PRINT "This is line 0050"

10 REM RESTORE Example
20 DATA 0.76,3.55,7.80,2.65,9.52
25 DATA 9.96,6.32,8.15,6.61,9.73
30 FOR i = 1 TO 4
40 READ a
50 PRINT a
60 NEXT i
70 RESTORE 20
80 FOR j = 1 TO 4
90 READ b
100 PRINT b
110 NEXT j

10 REM RETURN Example
20 PRINT "Beginning of Program"
30 GOSUB 0060 // Subroutine # 1
40 PRINT "End of Program"
50 END
60 REM Subroutine #1
70 PRINT "Here I am!"
80 RETURN

10 REM ROUND Example
20 REM ROUNDS three numbers and adds them together.
30 PRINT "Please enter three numbers"
40 INPUT Number1,Number2,Number3
50 Total = ROUND(Number1) + ROUND(Number2) + ROUND(Number3)
60 PRINT "The Total is = " ; Total

10 REM Run Example
20 INPUT a
30 atEnd: PRINT a

10 REM SENDIRREMOTE Example
20 t="01000101101110101110100000010111"
30 trans=[0,500,14,50,14,0,8]
35 zero="0"[0] // char 0 (not string 0)
40 FOR i=0 TO strLen(t)-1
50 ADDARRAYSLOT(trans,1)
60 IF t[i]=zero THEN ADDARRAYSLOT(trans,1) ELSE ADDARRAYSLOT(trans,3)
70 NEXT i
80 ADDARRAYSLOT(trans,1)
90 ADDARRAYSLOT(trans,1)
100 SENDIRREMOTE(trans,1)

10 REM SETBOUNDS Example
20 W1Spec={viewBounds: SETBOUNDS(10, 50, 200, 80)}
30 WINDOW Win1, W1Spec
40 SHOW Win1

10 REM SETICON Example
20 ws := {viewBounds: SETBOUNDS(100, 132, 100, 132)}
30 shape := [MAKERECT(1,1,30,30), MAKETEXT("$",12,10,21,21)]
40 icon:=MAKEBITMAP(32,32,NIL)
50 DRAWINTOBITMAP(shape,NIL,icon)
60 SETICON "INVEST",icon

10 REM SETVALUE Example
20 W1Spec={viewBounds:Â
   SETBOUNDS(10,50,200,80)}
30 WINDOW Win1, W1Spec, "LabelInput"
40 SHOW Win1
50 FOR i = 1 TO 10
60 SETVALUE(W1Spec.entryline, 'text,Â
   "Number: " &i)
70 WAIT 100
80 NEXT i
90 HIDE Win1

10 REM SHOW Example
20 W1Spec := {ViewBounds: Â
SETBOUNDS(10, 50, 100, 100)}
30 W2Spec := {ViewBounds: Â
SETBOUNDS(20, 70, 100, 100)}
40 WINDOW Win1, W1Spec
50 WINDOW Win2, W2Spec
60 WPRINT Win1, "Window 1"
70 WPRINT Win2, "Window 2"
80 SHOW [Win1, Win2]
90 WAIT
100 HIDE Win2
110 SHOW Win2
120 HIDE

10 REM SIGNUM Example
20 PRINT "Please enter a number"
30 INPUT X
40 PRINT "SIGNUM of x is = " ; SIGNUM(X)

10 REM SIN Example
20 PRINT "Please enter an angle"
30 INPUT Angle
40 PRINT "The Sine of the angle is = " ; SIN(Angle) ; " radians"

10 REM SORT an array Example
20 DIM A[3]
30 A[0]=23
40 A[1]=5
50 A[2]=54
60 A=SORT(A,'|<|,NIL)
70 PRINT A[0],A[1],A[2]

10 REM SORT of array of frames Example
15 DIM a[4]
20 a[0] := {name: "Arthur", seq: 2}
30 a[1] := {name: "Ford", seq: 3}
40 a[2] := {name: "Trill", seq: 1}
50 a[3] := {name: "Zaphod", seq: 4}
60 a=SORT(a,'|<|, 'seq)
70 FOR i=0 TO 3
80 PRINT a[i].name
90 NEXT i

10 REM SQRT Example
20 REM This program returns the square root of the number entered at the prompt.
30 PRINT "Please enter a number"
40 INPUT Number
50 PRINT "Square root = " ; SQRT(Number)

10 REM STOP Example
20 PRINT "First Program Section"
30 STOP
40 PRINT "Second Program Section"

10 REM STRCOMPARE Example
20 REM User enters two items which are forced into strings. Computer compares them.
30 PRINT "Please enter item 1"
40 INPUT String1$
50 PRINT "Please enter item 2"
60 INPUT String2$
70 Result = STRCOMPARE(String1$, String2$)
80 IF Result = 0 THEN PRINT "Strings are Equal"
90 IF Result > 0 THEN PRINT "Second string is larger"
100 IF Result < 0 THEN PRINT "First string is larger"

10 REM STREQUAL Example
20 REM User enters two items which are forced into strings. Computer compares them.
30 PRINT "Please enter item 1"
40 INPUT String1$
50 PRINT "Please enter item 2"
60 INPUT String2$
70 Result = STREQUAL(String1$, String2$)
80 IF STREQUAL(String1$, String2$) THEN PRINT "Strings are Equal" ELSE PRINT "Strings are not Equal"

10 REM STRINGER Example
20 REM Concatenates 3 array elements 
30 DIM Array[3]
40 FOR i = 0 TO 2
50 PRINT "Please enter something"
60 INPUT Element
70 Array[i] = Element
80 NEXT i
90 PRINT "The result is..."
100 PRINT STRINGER(Array)

10 REM STRINGTONUMBER Example
20 REM Places two "string" numbers together and adds 5 to that number.
30 PRINT "Please enter 2 numbers"
40 INPUT Number1$,Number2$
50 NewNumber = Number1$ & Number2$
60 PRINT "The numbers concatenated are... " ; NewNumber
70 PRINT "The Numbers with 5 added are... " ; STRINGTONUMBER(NewNumber)+5

10 REM STRINGTOTIME Example
20 theTime = STRINGTOTIME("3:40 pm")
30 PRINT theTime

10 REM STRLEN Example
20 PRINT "Enter a String"
30 INPUT string$
40 PRINT "There are " ; STRLEN(String$) ; " characters in the string"

10 REM STRPOS Example
20 REM Looks for a substring in a user defined string.
30 PRINT "Please enter a string"
40 INPUT String
50 PRINT "Please enter a string to look for"
60 INPUT Substring
70 Result = STRPOS(String,Substring,0)
80 IF Result = NIL THEN PRINT "Substring not found" ELSE PRINT "Substring is at character " ; Result

10 REM SUBSTR Example
20 REM Creates a substring from the first 5 characters of a string.
30 PRINT "Please enter a string"
40 INPUT String
50 Result = SUBSTR(String, 0, 4)
60 PRINT "The new substring is " ; Result

10 REM TAN Example
20 PRINT "Please enter an angle"
30 INPUT Angle
40 PRINT "The tangent of the angle is = " ; TAN(Angle) ; " radians"

10 REM TICKS Example
20 Oldtime = TICKS()
30 PRINT "Tap any key, then the enter key when ready"
40 INPUT A$
50 Newtime = TICKS()
60 PRINT (Newtime-Oldtime) / 60 ; " Seconds passed"

10 REM TIME Example
20 PRINT "The Number of Minutes passed since 01/01/04 is..." ; TIME()
30 PRINT "The Current Date and Time is " ; DATENTIME(TIME())

10 REM TIMESTR Example
20 theTime = TIME()
30 PRINT TIMESTR(theTime, 0)
40 PRINT TIMESTR(theTime, 1)
50 PRINT TIMESTR(theTime, 2)
60 PRINT TIMESTR(theTime, 3)
70 PRINT TIMESTR(theTime, 4)

10 REM TRACE Example
20 PRINT "This is an EXAMPLE"
30 PRINT "Llamas"
40 TRACE ON
50 FOR i = 1 TO 3
60 PRINT i
70 NEXT i
80 TRACE OFF
90 PRINT "End of program reached."

10 REM WAIT Example
11 f := {GOTO:'toggleCheck, Â
viewBounds: SETBOUNDS(100, 100, 110, 110)}
15 CLS
20 WINDOW w1,f
30 SHOW w1
40 FOR i=1 TO 3
45 PRINT i
50 WAIT
70 NEXT i
80 STOP
1000 toggleCheck: REM toggle checkbox
1010 cbox = NOT cbox
1020 IF cbox THEN WPRINT w1, CHR(8730) Â
ELSE WPRINT w1,""

10 REM WDRAW Example
20 W1Spec={viewBounds: Â
SETBOUNDS(10, 10, 150, 75)}
30 WINDOW WinNum, W1Spec
40 SHOW WinNum
50 WDRAW WinNum, [MAKELINE(55,15,75,45),Â
MAKEOVAL(10,10,40,40)], {penSize:2,Â
penPattern:vfGray, fillPattern:vfBlack}

10  REM WIDGETDEF Example
20  appSpec={goto:'endProgram,title: "WIDGETDEF Example"}
30  WINDOW app,appSpec,"APP"
40  SHOW app
50  widgetdef Layout_0 :={Byebtn:{widgetType:"textButton",order:Â
0,Goto:'bye,viewBounds:{left:141,top:199,right:200,bottom:Â
214},viewFlags:514,text:"Bye",viewFont:{family:'espy,face:1Â
, size:9},viewFormat:67109456}}
60  WINDOW wlist,Layout_0
70  SHOW wlist
100  WAIT -1 // indefinitely
9000 endProgram: REM
9005 bye: REM
9010  HIDE
9020  STOP

10 REM WINDOW Example
20 W1Spec := {viewbounds: SETBOUNDS(10, 50, 150, 75), viewFont: {family: 'espy, face: 7, size:14}, viewFormat: 4*vfRound +2*vfPen +vfFrameBlack+vfFillWhite, viewJustify: 2}
30 WINDOW WinNum, W1Spec
40 SHOW WinNum
50 WPRINT WinNum, "Slartybartfast"

10 REM WPRINT Example
20 W1Spec := {viewbounds: SETBOUNDS(10, 50, 150, 75), viewFont: {family: 'espy, face: 7, size:14}, viewFormat: 4*vfRound +2*vfPen +vfFrameBlack+vfFillWhite, viewJustify: 2}
30 WINDOW WinNum, W1Spec
40 SHOW WinNum
50 WPRINT WinNum, "Slartybartfast"

0010  REM Widget Example
0020  appSize := getappparams().appAreaBounds
0030  w1Spec := {Title: "Widget Example", Â
      GOTO:'appDone, GOSUBinfo: 'showInfo}
0040  w2Spec:={text:"\uFC01\u Show",Â
      GOSUB:'showButtonTap, viewBounds:Â
      SETBOUNDS(appSize.left+26,Â
      appSize.bottom-19, appSize.left+70,Â
      appSize.bottom-6), viewFont: Â
      {family:'espy, face:1, size:9},Â
      viewFormat:67109457}
0050  WINDOW w1, w1Spec, "APP"
0060  WINDOW w2, w2Spec, "TEXTBUTTON"
0070  SHOW w1, w2
0080  WAIT -1
0090 appDone: REM tapped close box
0100  HIDE
0110  PRINT "Closed."
0120  END
0130 showInfo: REM Info button tapped
0140  popBounds := Â
           U.w1Spec.base.appInfo:GLOBALBOX()
0150  popBounds.left = popBounds.right+2
0160  iPopSpec := {GOSUB:'pickiChosen, Â
      pickItems:["About","Help","Prefs"],Â
      Bounds:popBounds}
0170  WINDOW wInfo, iPopSpec, "PICKER"
0180  SHOW wInfo
0190  RETURN
0200 pickiChosen: REM Picked
0210  ON (iPopSpec.viewValue + 1) Â
      GOTO iAbout,iHelp,iPrefs
0220  iAbout: Notify("About", Â
      "This is an example.")
0230  RETURN
0240  iHelp: Notify("Help", Â
      "There is no Help.")
0250  RETURN
0260  iPrefs: Notify("Prefs", Â
      "There are no Prefs.")
0270  RETURN
0280 showButtonTap: REM
0290  popBounds := Â
           U.w2Spec:GLOBALBOX()
0300  popBounds.left = popBounds.right+2
0310  showSpec := {GOSUB:'pickShowChosen, Â
      pickItems:["Some","Most","All", Â
      'PICKSOLIDSEPARATOR, "Less", "More"],Â
      Bounds:popBounds}
0320  WINDOW wShow, showSpec, "PICKER"
0330  SHOW wShow
0340  RETURN
0350 pickShowChosen: REM
0360   Notify("Show", "Option \"" & Â
       showSpec.pickItems[showSpec.viewValue]Â
       & "\" is not implemented!")
0370  RETURN

0010  REM Visual Designer Example
0020  appSize := getappparams().appAreaBounds
0030  w1Spec := {Title: "Widget Example", Â
      GOTO:'appDone, GOSUBinfo: 'showInfo}
0040  w2Spec:={text:"\uFC01\u Show",Â
      GOSUB:'showButtonTap,Â
      viewBounds: SETBOUNDS(appSize.left+26,Â
      appSize.bottom-19,  appSize.left+70, Â
      appSize.bottom-6), viewFont:Â
      {family:'espy, face:1, size:9},Â
      viewFormat:67109457}
0050  WINDOW w1, w1Spec, "APP"
0060  WINDOW w2, w2Spec, "TEXTBUTTON"
0062  WIDGETDEF layout_some :={DatePicker:{widgetType:"datePicker"Â
,order:0,viewBounds:{top:55,bottom:135,left:4,right:124},viÂ
ewFlags:512,selectedDates:[48864486]},Widget_0:{widgetType:Â
"title",order:1,viewBounds:{left:4,top:28,right:111,bottom:Â
45},viewJustify:0,viewFont:{family:'espy,face:1,size:12},viÂ
ewFlags:1,text:"Show Some!",viewFormat:0},checkBox:{widgetTÂ
ype:"checkbox",order:2,viewValue:NIL,text:"Some Option",vieÂ
wBounds:{left:8,top:147,right:108,bottom:167},viewFlags:512Â
,viewFont:{family:'espy,face:0,size:10},viewJustify:4},WidgÂ
et_3:{widgetType:"newSetClock",order:3,viewBounds:{left:15,Â
top:173,right:78,bottom:236},viewFlags:512,minutes:6,hours:Â
16},dateToggle:{widgetType:"textButton",order:4,GOSUB:'toggÂ
leDate,viewBounds:{left:141,top:88,right:200,bottom:103},viÂ
ewFlags:514,text:"Hide Date",viewFont:{family:'espy,face:1,Â
size:9},viewFormat:67109456}}
0064  WINDOW win_some, layout_some
0070  SHOW w1, w2
0075  layout_visible = NIL
0080  WAIT -1
0090 appDone: REM tapped close box
0100  HIDE
0110  PRINT "Closed."
0120  END
0130 showInfo: REM Info button tapped
0140  popBounds := Â
      U.w1Spec.base.appInfo:GLOBALBOX()
0150  popBounds.left = popBounds.right+2
0160  iPopSpec := {GOSUB:'pickiChosen, Â
      pickItems: ["About","Help",Â
      "Prefs"], Bounds:popBounds}
0170  WINDOW wInfo, iPopSpec, "PICKER"
0180  SHOW wInfo
0190  RETURN
0200 pickiChosen: REM Picked
0210  ON (iPopSpec.viewValue + 1) Â
      GOTO iAbout,iHelp,iPrefs
0220   iAbout: Notify("About", Â
       "This is an example.")
0230  RETURN
0240   iHelp: Notify("Help",  Â
       "There is no Help.")
0250  RETURN
0260   iPrefs: Notify("Prefs",  Â
       "There are no Prefs.")
0270  RETURN
0280 showButtonTap: REM
0290  popBounds := Â
      U.w2Spec:GLOBALBOX()
0300  popBounds.left = popBounds.right+2
0310  showSpec := {GOSUB:'pickShowChosen,Â
      pickItems: ["Some","Most","All", Â
      'PICKSOLIDSEPARATOR, "Less", Â
      "More"], Bounds:popBounds}
0315  IF layout_visible <> NIL THEN Â
      showSpec.pickItems[layout_visible-1]:=Â
      {item:showSpec.pickItems[Â
      layout_visible-1],Â
      pickable: TRUE,mark: CHR(8730)}
0320  WINDOW wShow, showSpec, "PICKER"
0330  SHOW wShow
0340  RETURN
0350 pickShowChosen: REM
0355  IF layout_visible <> NIL THEN Â
      ON layout_visible Â
      GOSUB save_some, save_most
0357  layout_visible = showSpec.viewValue + 1
0358  IF showSpec.viewValue = 0 THEN
0360     SHOW win_some
0361  ELSE
0362     Notify("Show", "Option \""Â
         & showSpec.pickItems[Â
         showSpec.viewValue] & Â
         "\" is not implemented!")
0363  END IF
0370  RETURN
1000 save_some: REM
1010  PRINT "Values from layout layout_some:"
1020  PRINT "Date: " & DATENTIME(Â
      layout_some.DatePicker.selectedDates[0])
1030  IF layout_some.checkbox.viewValue Â
      THEN PRINT "Checkbox is checked" Â
      ELSE PRINT "Checkbox is NOT checked"
1040  PRINT "Hours: "; Â
      layout_some.Widget_3.hours; ",  Â
       Minutes: ";  Â
       layout_some.Widget_3.minutes
1050  HIDE win_some
1060  RETURN
2000 toggleDate: REM
2010  IF layout_some.dateToggle.text =  Â
      "Hide Date" THEN
2020    SETVALUE(layout_some.dateToggle,  Â
        'text, "Show Date")
2030    HIDE win_some[ Â
        layout_some.DatePicker.order]
2040  ELSE
2050     SETVALUE(layout_some.dateToggle,  Â
        'text, "Hide Date")
2060    SHOW win_some[ Â
        layout_some.DatePicker.order]
2070  END IF
2080  RETURN
3000 save_most: REM
3010 RETURN

10  REM APP Example
20  w1Spec := {Title: "App Example", Â
      GOTO:'appDone, GOSUBinfo: 'showInfo}
30  WINDOW w1, w1Spec, "APP"
40  SHOW w1
50  WAIT -1
100 appDone: REM tapped close box
110  HIDE
120  PRINT "Closed."
130  END
200 showInfo: REM Info button tapped
210  popBounds := Â
     U.w1Spec.base.appInfo:GLOBALBOX()
220  popBounds.left = popBounds.right+2
230  w2Spec = {GOSUB:'pickChosen, pickItems:Â
  ["About","Help","Prefs"], Bounds:popBounds}
240  WINDOW w2, w2Spec, "PICKER"
250  SHOW w2
260  RETURN
300 pickChosen: REM Picked
310  PRINT "You picked item: ";Â
      w2Spec.viewValue
320  RETURN

10  REM AZTABS Example
20  w1Spec := [{Title: "AZTABS Example", Â
    GOTO:'appDone, widgetType:"APP"},Â
    {GOSUB: 'azDone, viewBounds: Â
    SETBOUNDS(0,30,0,51), Â
    widgetType:"AZTABS"}]
30  WINDOW w1, w1Spec
40  SHOW w1
50  WAIT -1
60 azDone: REM A selection was made
70  PRINT "Index: "; w1Spec[1].curIndex; ", Â
      Text: ", w1Spec[1].text
80  RETURN
100 appDone: REM tapped close box
110  HIDE
120  PRINT "Closed."
130  END

10 REM CHECKBOX Example
20 w1Spec := {}
30 WINDOW w1, w1Spec, "CHECKBOX"
40 w2Spec := {viewValue: true}
50 WINDOW w2, w2Spec, "RCHECKBOX"
60 SHOW w1, w2

10 REM CLOSEBOX Example
20 w1Spec := {GOTO: 'appDone}
30 WINDOW w1, w1Spec, "CLOSEBOX"
40 SHOW w1
50 WAIT -1
100 appDone: REM tapped close box
110 HIDE
120 PRINT "Tapped."

10 REM DATEPICKER Example
20 w1Spec = {GOTO: 'dateSelected}
30 WINDOW w1, w1Spec, "DATEPICKER"
40 SHOW w1
50 w1Spec.selectedDates := [4870000]
60 U.w1Spec:REFRESH()
70 WAIT -1
100 dateSelected: REM tapped a date
110 HIDE
120 PRINT DATENTIME(w1Spec.selectedDates[0])

10 REM DIGITALCLOCK Example
20 w1Spec = {GOTO:'timeChanged, Â
time: STRINGTOTIME("3:10PM")}
30 WINDOW w1, w1Spec, "DIGITALCLOCK"
40 SHOW w1
100 timeChanged: REM Time changed
110 PRINT TIMESTR(w1Spec.time, 0)

10  REM DRAW Example
20  w1Spec = {viewBounds: Â
    SETBOUNDS(20,20,200,200)}
30  WINDOW w1, w1Spec, "DRAW"
40  SHOW w1

10 REM GAUGE Example
20 w1Spec = {viewValue:0}
30 WINDOW w1, w1Spec, "GAUGE"
40 SHOW w1
50 FOR i = 1 TO 100
60 w1Spec.viewValue = i
70 WPRINT w1, ""
80 NEXT i

10 REM GLANCE Example
20 w1Spec = {text:"Read me quickly"}
30 WINDOW w1, w1Spec, "GLANCE"
40 SHOW w1

10  REM LABELINPUT Example
20  w1Spec = {viewBounds:SETBOUNDS(20,20,200Â
    ,45),labelCommands:["one", "2", "three"]}
30  WINDOW w1, w1Spec, "LABELINPUT"
40  SHOW w1

10 REM LABELPICKER Example
20 w1Spec = {labelCommands:Â
   ["one", "two", "three"]}
30 WINDOW w1, w1Spec, "LABELPICKER"
40 SHOW w1

10 REM MONTH Example
20 w1Spec:={viewBounds:SETBOUNDS(10,Â
   10,115,80)}
30 WINDOW w1, w1Spec, "MONTH"
40 SHOW w1

10 REM NEWSETCLOCK Example
20 w1Spec := {GOTO: 'clockSel, viewBounds:Â
   SETBOUNDS(20,20,80,80)}
30 WINDOW w1, w1Spec, "NEWSETCLOCK"
40 SHOW w1
50 END
100 clockSel: REM A selection was made
110 PRINT "Hours: "; w1Spec.hours; ",Â
    Minutes: "; w1Spec.minutes

10 REM NUMBERPICKER Example
20 w1Spec = {GOTO: 'numberChanged, value: 0}
30 WINDOW w1, w1Spec, "NUMBERPICKER"
40 SHOW w1
50 END
100 numberChanged: REM value changed
110 PRINT "Value is: "; w1Spec.value

10 REM PARAGRAPH Example
20 w1Spec = {viewBounds:SETBOUNDS(20,20,Â
   200,200)}
30 WINDOW w1, w1Spec, "PARAGRAPH"
40 SHOW w1

10 REM PICKER Example
20 w1Spec = {GOTO: 'pickChosen, pickItems: ["a","b","c"]}
30 WINDOW w1, w1Spec, "PICKER"
40 SHOW w1
50 WAIT // with 5 second timeout
60 END
200 pickChosen: REM Picked
210 PRINT "You picked item: "; w1Spec.viewValue

10 REM PICTUREBUTTON Example
20 shape := [MAKERECT(1,1,30,30),Â
   MAKETEXT("I",12,10,21,21)]
30 myIcon:=MAKEBITMAP(32,32,NIL)
40 DRAWINTOBITMAP(shape, NIL, myIcon)
50 w1Spec = {icon: myIcon, GOTO: 'buttonTap,Â
   viewBounds: SETBOUNDS(101, 101, 132, 132)}
60 WINDOW w1, w1Spec, "PICTUREBUTTON"
70 SHOW w1
80 WAIT -1
200 buttonTap: REM tapped button
210 HIDE
220 PRINT "Tapped."

10 REM SCROLLER Example
20 w1Spec = {text: "You can..."}
30 WINDOW w1, w1Spec, "SCROLLER"
40 SHOW w1

10 REM SETCLOCK Example
20 w1Spec := {viewBounds:SETBOUNDS(20,20,83,Â
   83)}
30 WINDOW w1, w1Spec, "SETCLOCK"
40 SHOW w1

10 REM SLIDER Example
20 w1Spec := {viewBounds:SETBOUNDS(20,20,90,Â
   30)}
30 WINDOW w1, w1Spec, "SLIDER"
40 SHOW w1

10 REM TEXT Example
20 w1Spec = {text: "Input..."}
30 WINDOW w1, w1Spec, "TEXT"
40 SHOW w1

10 REM TEXTBUTTON Example 
20 w1Spec:={text:"Tap Me!",GOTO:'buttonTap,Â
   viewBounds: SETBOUNDS(20, 20, 70, 35)}
30 WINDOW w1, w1Spec, "TEXTBUTTON"
40 SHOW w1
50 WAIT -1
100 buttonTap: REM tapped button
110 HIDE
120 PRINT "Tapped."

10  REM TEXTLIST Example
20  w1Spec:={viewBounds:SETBOUNDS(20,20,200,Â
    80),listItems:[],useScrollers:TRUE,Â
    useMultipleSelections:TRUE,Â
    ScrollAmounts:[1,3,20]}
30  WINDOW w1, w1Spec, "TEXTLIST"
40  SHOW w1
50  WAIT
60  w1Spec.listItems := ["A","B","C",Â
    "D is a long item", "E", "F"]
70   U.w1Spec:SETUPLIST()
80   U.w1Spec:REDOCHILDREN()
90  WAIT
100  w1Spec.useMultipleSelections=NIL
110  U.w1Spec:REDOCHILDREN()

10 REM TITLE Example
50 w1Spec = {viewBounds: SETBOUNDS(20,20,Â
   120,60), text: "Sample Title"}
60 WINDOW w1, w1Spec, "TITLE"
70 SHOW w1

10 REM frame Example
20 REM myUser is a variable holding
30 REM all the info for a user
40 myUser = {} // an empty container
50 PRINT "Enter your first name:"
60 INPUT name$
70 myUser.firstName = name$
80 PRINT myUser // see elements added
90 PRINT "Enter your last name:"
100 INPUT name$
110 myUser.lastName = name$
120 PRINT myUser // see another element!
130 PRINT "Enter your age, or S to Skip:"
140 INPUT age$
150 IF age$ = "S" THEN GOTO 170
160 myUser.age = STRINGTONUMBER(age$)
170 PRINT myUser // final form
180 PRINT "First Name: "; myUser.firstName
190 PRINT "Last Name: "; myUser.lastName
200 IF myUser.age = nil THEN GOTO 220
210 PRINT "Age: "; myUser.age
220 PRINT "Try again? (Y/N):"
230 INPUT ans$
240 IF ans$ = "Y" THEN GOTO 30

10 REM File/Key retrieval Example
20 REM OPEN or CREATE a file...prompts forÂ
some information, stores it, then allowsÂ
the user to fetch records.
30 OPEN chan, "EXAMPLEFile", keyname
40 IF FSTAT = 1 THEN Â
CREATE chan, "EXAMPLEFile", keyname
50 IF FSTAT =1 THEN GOTO 300
60 PRINT "Please enter a Key, Q to finish"
70 INPUT FileKey$
80 IF FileKey$ = "Q" THEN GOTO 210
90 fileRecord = {}
100 fileRecord.keyname = FileKey$
110 PRINT "Please enter some data for this Key"
120 INPUT FileData
130 fileRecord.info = FileData
140 PRINT "Enter a number, or S to Skip:"
150 INPUT num$
160 IF num$ = "S" THEN GOTO 180
170 fileRecord.num = STRINGTONUMBER(num$)
180 PUT chan, fileRecord
190 IF FSTAT=1 THEN STOP
200 GOTO 60
210 PRINT "Please enter a Key to find, Q to end"
220 INPUT FileKey$
230 IF FileKey$ = "Q" THEN GOTO 290
240 GET chan,FetchedData,FileKey$
250 IF FSTAT=1 THEN STOP
260 IF FSTAT=2 THEN PRINT Â
"Not found! Close Record is..." Â
ELSE PRINT "Data is..."
270 PRINT FetchedData
280 GOTO 210
290 END
300 REM error, cannot OPEN or CREATE file!
310 PRINT "Error! Cannot OPEN or CREATE EXAMPLEfile."
320 END

10 REM simple user entry of a number
20 REM without error checking
30 PRINT "enter your age"
40 INPUT age
50 dogAge = age * 7
60 PRINT "You are "; dogAge; " in Dog Years!"








Last modified: January 14, 1997
NS BASIC Corporation
Phone: 416 264-5999 Fax: 416 264-5888
Internet: info© nsbasic.com