NS BASIC Tech Note                                     October 16, 1996

29. How to access NewtonPress¨                     
--------------------------------------------------------------------------

Apple provides a useful application called NewtonPress. It allows you to 
take
text and graphics on your host PC or Mac, and turn them into a downloadable
package that you can use on your Newton. The form of the package is a 
Newton
Book. While data formatted this way can be read easily using the Newton's 
built
in functionality, it is also a great way to download data that NS BASIC 
can use.
Here is some information on how to do so.

A. Extracting data from Newton Press¨ documents

Using NS BASIC, itÕs easy to access data that has been downloaded to the 
Newton
that has been created by Newton Press. (By the way, Newton Press, from 
Apple, is
an indispensable application for lots of other uses). This makes a 
convenient way
to download databases. HereÕs some sample code that extracts information 
from a
package named ÔAddress ExportÕ which is on the card:

0010 rem get data from NewtonBook
0020 LET pkgRef:=getPkgRef("Address Export",getstores()[1])
0030 LET pkgInfo:=getPkgRefInfo(pkgRef)
0040 LET dataFile:=pkgInfo.parts[0].book.contents[0].data

The variable dataFile will contain the complete object that was 
downloaded. If
the data was download as text, dataFile will be a normal string variable 
that is
read only.

To quickly the data into an NS BASIC data structure, you can use the 
following
method. Format the data on the host system so it is in the form of Newton 
frames.
HereÕs what the sample data would look like:

"{Name: "Arthur Dent ", Country: "England ", phone: "44 1 333 4444 "}
{more records...}"

Now, from NS BASIC, do the following:

0050 record=substr(dataFile,a,b) // get a portion of dataFile
0060 x=compile(record)
0070 addressFrame=u:x()

AddressFrame will now contain the data appropriately converted into normal 
frames.

If your data comes in fixed length format and is read only, you can treat
dataFile as a single large file, using an expression like 
record=substr(dataFile,
recordNumber*recordLen, recordLen) to quickly access records from the file.


B. Downloading Graphics to NS BASIC using Newton Press¨

Another use for NS BASIC with Newton Press is as a way to download 
graphics or
pictures. Once downloaded, these pictures can be stored in files (imagine 
a parts
inventory with pictures, or a photo album), or used as icons and buttons. 
HereÕs
how to download a map:

First, paste the map into Newton Press and save it as a package called 
map.pkg.
Download the package. YouÕll see it in the Extras Drawer.

Next, use the following code to extract the picture and put it into an NS 
BASIC
widget:

0010 rem get graphic from NewtonBook
0020 LET pkgRef:=getPkgRef("map.pkg",getstores()[1])
0030 LET pkgInfo:=getPkgRefInfo(pkgRef)
0040 LET map:=pkgInfo.parts[0].book.contents[0].data
1020 LET ws.viewBounds:={left: 80, right: 140, top: 10, bottom: 200}
1030 window w,ws
1050 show w
1100 U.ws:copyBits(map,0,0,nil)


C. ENTER and NewtonPress

The ENTER command has been enhanced to extract programs and commands from
packages created using NewtonPress. On your PC or Mac, create a file with 
NS
BASIC statements and commands and paste it into NewtonPress. (You can also 
type
directly into NewtonPress.) Use NewtonPress to create a package and 
download it.
When you use the ENTER command with the name of the package, each line in 
that
package will be read in turn and interpreted. A progress bar will show as 
this is
going on.

This feature is a useful way to download one or more programs, with SAVE
statements embedded. It is also a way of constructing a command list of NS 
BASIC
commands. (Available starting with NS BASIC 3.60)