Other Examples of NS BASIC Code


This is sample code to do a number of things. These samples are not in the manual. Feel free to cut and paste this code into your Newton to give it a try.

Contents

  1. Pass output to the QCHART
  2. Open other applications from NS BASIC
  3. How to access elements of a frame
  4. Write to the calendar application
  5. Write to the To do application
  6. Write to the Notepad
  7. List a program to the Notepad
  8. List the contents of Quickfigure spreadsheet to the screen
  9. Dump all notes to the serial port
  10. Do a checkbox: this is simply a clickable window.
  11. Demonstrate recognition modes

Code Samples

1. Pass output to the QCHART module of Quickfigure and produce charts and graphs.
0010 LET a=[1,2,5,4,3,1,2,3,4,5]
0020 LET getroot().|qf_qchart:donv|.ddxdata=a
0021 LET getroot().|qf_qchart:donv|.rows=5
0022 LET getroot().|qf_qchart:donv|.cols=2
0030 LET getroot().|qf_qchart:donv|.ddxfrom='|basic:nsbasic|
0040 LET x:=getroot().|qf_Qchart:donv|:open()

2. Open other applications from NS BASIC

0010 a:=getroot().|qfig:donv|:open()

3. How to access elements of a frame

0010 REM demonstrate variable referencing
0020 LET X={A: 1, B: 2, C: 3}
0030 LET Y=intern("B")
0040 PRINT X.(Y)
0050 LET GG:=getglobals()
0060 Y=ELEMENTS(GG)
0070 FOR I=0 TO length(GG)-1
0080    PRINT Y[I], GG.(intern(y[i]))
0090 NEXT I

Output:
2
...
trace
U
userConfiguration

4. Write to the calendar application

0010 rem write to Calendar
0020 open ch,"calendar",mtgstartdate
0030 LET n={}
0040 LET n.viewstationery='meeting
0055 LET x=stringtodate("9:00 6/3/94")
0060 LET n.mtgstartdate=x
0070 LET n.mtgtext="Meet with Bob"
0080 LET n.mtgduration=30
0110 put ch,n
0120 if fstat>0 then stop

5. Write to the To do application

0010 rem write to To Do
0020 open ch,"To Do",mtgstartdate
0030 LET n={data:[{}]}
0040 LET n.viewstationery='todoitem
0050 LET n.height=100
0060 LET n.mtgstartdate=time()
0065 LET n.mtgpriority=0
0070 LET n.data[0].viewstationery='para
0080 LET n.data[0].viewbounds={left:0, right:200, top:0, bottom:100}
0090 LET n.data[0].text="Hello World"
0091 LET n.data[0].mtgdone=nil
0095 LET n.data[0].viewfont=getglobals().userconfiguration.userfont
0100 LET n.timestamp=time()
0110 put ch,n
0120 if fstat>0 then stop

6. Write to the Notepad

0010 rem write to notepad
0020 open ch,"notes",timestamp
0030 LET n={data:[{}]}
0040 LET n.viewstationery='paperroll
0050 LET n.height=100
0070 LET n.data[0].viewstationery='para
0080 LET n.data[0].viewbounds={left:0, right:200, top:0, bottom:100}
0090 LET n.data[0].text="Hello World"
0095 LET n.data[0].viewfont=getglobals().userconfiguration.userfont
0100 LET n.timestamp=time()
0110 put ch,n
0120 if fstat>0 then stop

7. List a program to the Notepad

0010 rem list a program to notepad
0020 open pch,"notes.Bas:NSBASIC",lineno
0030 LET x=""
0040 get pch,stmt
0050 if Stmt.text=nil Then goto 100
0060 LET x=x & Stmt.lineno & " " & Stmt.text & chr(13)
0070 GOTO 0040
0100 rem end of stmts
0110 GOSUB 1000
0120 stop
1000 rem write to notepad
1020 open ch,"notes",timestamp
1030 if fstat>0 then stop
1040 LET n={data:[{}]}
1050 LET n.viewstationery='paperroll
1060 LET n.height=1000
1070 LET n.data[0].viewstationery='para
1080 LET n.data[0].viewbounds={left:0, right:200, top:0, bottom:100}
1090 LET n.data[0].text=x
1100 LET n.data[0].viewfont=getglobals().userconfiguration.userfont
1110 LET n.timestamp=time()
1120 put ch,n
1130 if fstat>0 then stop
1140 return

8. List the contents of Quickfigure spreadsheet to the screen
0010 rem List contents of spreadsheet
0015 open ch,"qfig:donv"
0020 get ch,f1
0030 get ch,f2
0050 LET x=elements(f1.values)
0060 for i=0 to length(x)-1
0070   LET y=intern(x[i])
0080   PRINT x[i],f1.values.(y),f2.data.(y).formula
0100 next i

9. Dump all notes to the serial port

0010 rem dump all notes to serial port
0020 open ch,"notes",timestamp
0025 environ io="s0"
0030 get ch,n
0040 if fstat=1 then goto 9000
0043 print datentime(n.timestamp)
0045 for i=0 to length(n.data)-1
0050   print n.data[i].text
0055 next i
0057 print " "
0060 GOTO 0030
9000 rem fin
9010 environ io="screen"

10. Do a checkbox: this is simply a clickable window. (Note: using a checkbox window object is far more efficient)

0010 LET f={goto:1000}
0011 LET f.viewbounds={left:100, right:110, top: 100, bottom: 110}
0015 cls
0020 window w1,f
0030 show w1
0040 for i=1 to 3
0045   PRINT i
0050   wait
0070 next i
0080 stop
1000 rem toggle checkbox
1010 LET cbox=not cbox
1020 if cbox then wprint w1,chr(8730) else wprint w1,""

11. Demonstrate recognition modes

0010 rem demonstrate recognition modes
0020 cls
0030 LET recogs=[0, vNumbersAllowed, vPhoneField, vDateField, vTimeField, vMathAllowed]
0031 LET recogs[0]=vCharsAllowed+vPunctuationAllowed+vNumbersAllowed
0100 rem get popup for recog type
0110 LET w2s.viewBounds={left: 1, right: 200, top:20, bottom: 36}
0120 LET w2s.text="Recognition Type"
0130 LET w2s.labelcommands=["Anything","Number","Phone","Date","Time","Math"]
0131 LET w2s.index=0
0140 window w2,w2s,"LabelPicker"
0150 show w2
0200 rem set up input field
0210 LET w3s.viewBounds={left: 10, right: 230, top: 100, bottom: 200}
0220 LET w3s.viewFlags=vVisible+vClickable+vGesturesAllowed+recogs[w2s.index]
0230 LET w3s.text=""
0280 window w3,w3s,"Text"
0290 show w3

NS BASIC Corporation
Phone: 416 264-5999 Fax: 416 264-5888
Internet: info© nsbasic.com