Technote: Programs and Notes               -- May 23 1996

10: How to turn Notes into Programs
=========================================================

[Contributed by Henry Melton (hmelton© io.com) of Hutto, Texas]

One project that I wanted was the ability to move BASIC programs back and 
forth from notes to NSBASIC.  Moving programs in and out the serial port
is easy, and I think it can even be done over the IR port, but I wanted 
a totally standalone situation where I could build up programs from 
libraries
while at an airport or at lunch.  A sample program that writes 
programs to notes is in the documentation, but I wanted one that would 
read notes and make it into a program.  I have already turned all the 
sample program files into Paperback packages.  I wanted to cut and paste
interesting code into a  note and then read it in.

Well, I succeeded, in spite of the Create command only allowing string 
keys.
NSBASIC has the ability to LIST a program to a simple soup and then ENTER 
it back in allowing code merge.  I wrote a program that reads a note and
then writes it to this simple list soup.  To get around the inability to
Create the soup, I manually list a non-existant range of numbers to a
soup.  Here are the steps:

Paste the program into the only note in the BASIC folder.
in NSBASIC:
LIST 1,2,temp
RUN Notes2BAS
NEW
ENTER temp.txt


Here is the code to Notes2BAS for NS BASIC 3.0 and earlier:


0010 open o,"temp.txt",recNo
0060 LET r=0
0070 LET sym=intern("BASIC")
0080 open x,"notes"
0090 get x,y
0100 if fstat = 1 then end
0110 if y.labels=(sym) then gosub 0130
0120 GOTO 0090
0130 rem print contents
0140 for i=0 to length(y.data)-1
0150   LET a$= y.data[i].text
0160   GOSUB 0190 //Write Lines
0170 next i
0180 return
0190 REM Write Lines
0200 if strlen(a$) = 0 then return
0210 GOSUB 0250 //Write First Line
0220 if fstat > 0 then stop
0230 LET r=r+1
0240 GOTO 0200
0250 REM Write First Line
0260 LET ret$=chr(13)
0270 LET j=strpos(a$,ret$,0)
0280 if j=NIL then goto 0380
0290 LET b$=substr(a$,0,j)
0300 LET c$=substr(a$,j+1,NIL)
0310 print "writing",r,b$
0320 LET t={}
0330 LET t.recno=r
0340 LET t.text=b$
0350 put o,t
0360 LET a$=c$
0370 return
0380 print "writing",r,a$
0390 LET t={}
0400 LET t.recno=r
0410 LET t.text=a$
0420 put o,t
0430 LET a$=""
0440 return


Here is a program that puts a program into the Notes file.
This is for Rev 3.5 and higher: the program file layout has changed a bit.

10 REM List2Notes V2.1
20 LET defaultFont=0
30 LET f=getStores()[1]:getSoupNames()
40 LET b=["None -- Exit","All Programs"]
50 for i=0 to length(f)-1
60 LET r=strpos(f[i],":NSBASIC",0)
70 if r then addArraySlot(b,f[i])
80 next i
90 LET wb={Text:"BASIC 
Program",labelCommands:b,goto:0350,viewbounds:{left:10,right:200,top:50,bottom:80}}

100 window b1,wb,"labelpicker"
110 show b1
120 wait 1000
130 cls
140 print "    List to Notes -- Choose Program"
150 GOTO 0120
160 LET fname=b[wb.viewvalue]
170 LET ts=time()
180 open pch,fname,lineno
190 if fstat > 0 then bye
200 print fname&&"Copy started."
210 LET x=""
220 get pch,stmt
225 if fstat=1 then goto 260
230 if Stmt.text=nil Then goto 0220
235 If Stmt.lineno > 199999 Then LET nn=stmt.lineno - 200000
240 LET x=x&nn&&Stmt.text&chr(13)
250 GOTO 0220
260 close pch
270 open ch,"notes",timestamp
280 if fstat>0 then stop
290 LET 
n={class:'paperroll,data:[{ViewStationery:'para,viewBounds:{left:0,right:239,top:0,bottom:100},text:x}],viewstationery:'paperroll,height:1000,labels:'BASIC, 
timeStamp:ts}
300 If DefaultFont > 0 Then n.data[0].viewfont=defaultFont Else  
n.data[0].viewfont=getglobals().userconfiguration.userfont
310 put ch,n
320 if fstat > 0 then print "Failed." else print "Completed."
330 close ch
340 return
350 if wb.viewvalue = 0 then bye
360 if wb.viewvalue = 1 then goto 0390
370 GOSUB 0160
380 GOTO 0120
390 hide
400 LET ts=time()
410 for fx=2 to length(b)-1
420 LET fname=b[fx]
430 GOSUB 0180
440 LET ts=ts+1
450 next fx
460 bye