Comics Db Application Usage Comics Db Application Design Source Code Zip FileContact Me

Introduction

I (Kent Archie)wanted a program on my Newton 2100 to manage my comics collection. Well, I wanted to turn an accumulation of comics into a collection by creating an inventory. I wanted to collect title, publisher, issue, price and box number. While there are database and inventory programs for the Newton, I thought it would be more fun to make my own. 

This is a long (much longer than I thought it would be) presentation on a program that I don't use much and I doubt others can use it. But, when I was looking for examples of NSBasic code to help me get this to work, I couldn't find much. By piecing together things from the NSBasic book, the few examples I could find and the NewtonScript books I had, I got things to work. It is my hope that somebody might find this useful. Part of the payback for all the work others have done on the Newton and whose efforts have benefited me. Contact me at the address above if there are errors in either the code or the explanation or if I can answer any questions.

The code is copyright to me, but you are welcome to use it in whole or in part for any non-commercial purpose.

Many years ago, I bought a copy of NS Basic (still for sale, I think) but hadn't really gotten anywhere with it. I didn't like the forms editor as it created the Basic code for the form as one giant line. In Basic, to change any part of a line, you have to re-type the entire line. I also wanted a bit more control over the code than the form editor would give me. I thought about NewtonScript, but after reading a fair amount of the books on it, I decided the learning curve would be steeper than what I wanted to climb at that point. After I was finished, I think I was wrong.

I didn't want to deal with the editing nightmare of Basic so I build a development process that allowed me to write and edit the code using my favorite editor and convert the code into a form that could be processed by NS Basic. It was a little clumsy but much less frustrating. As I was learning how to use NS Basic at the same time, there were a number of re-writes and refactorings of the code and this would have been a horror to re-type in Basic. Editing without any kind of copy and paste is very tedious. I had to be careful because I made a few small changes to test things directly on the Newt and had to remember to make the same change back in the real source file.

The development Tool Chain

The toolchain started with a text file with the Basic code, without line numbers, on the Windows PC. All this stuff assumes a Windows development environment. It should all work fine on other operating systems, but I think NewtonPress only runs on Windows. Maybe NewtScape will work? You have to be able to create a Newton book to download the code to the Newt. Or maybe there is another way to import the code to NSBasic from the host. This is the way I did it.  This was passed through a Perl program that added the line numbers and then converted into a Newton Book using Newton Press. The book was downloaded to the Newton. NS Basic can import programs stored as Newton Books. The Newt was connected to the PC and I used a terminal program (HyperTerminal) to use the PC keyboard to control the Newton. The details of the process are below.

Here are a few lines of the source file so you can see what that looks like.

rem CREATE A NUMBERPICKER FOR CHOOSING PRICES AND WHICH BOX THE COMICS
rem ARE IN. ORIGINALLY, THE PRICES WERE A SOUP BASED LIST, BUT AFTER
rem TRYING IT, A NUMBERPICKER SEEMED EASIER.
makelabels: rem CREATE LABEL PICKERS
pricespec := {text:"Price",minvalue:-1,maxvalue:10000,value:0}
pricespec.showleadingzeros=nil
pricespec.viewbounds = setbounds(52,260,200,290)
window wins[0],pricespec,"numberpicker"
rem
boxspec := {text:"Box",gosub:'boxchosen}
boxspec.viewbounds = setbounds(221,296,299,316)
boxspec.labelcommands = [""] // ADD LIST OF BOXES LATER
window wins[1],boxspec,"labelpicker"
return // END OF makelabels

Adding the line numbers

The text file, in this case comics.txt, doesn't contain any line numbers. As such, the NS BASIC interpretor will not run it. To add the line numbers, I wrote a little Perl program (number.pl) to read the file, prepend line numbers and put the result in another file called comics2.txt. I run the program using Cygwin. This is a UNIX shell environment that runs under Windows. The code looks like this:

#!c:/Perl/bin/perl
# the source file is passed in through the command line
# like ./number.pl comics
# The source file is comics.txt and the output will be
# comics2.txt

# number lines in increments of 5
$count=5;
$from = $ARGV[0] . ".txt";
$to = $ARGV[0] . "2.txt";
# show the user what is being done
print "From ",$from," to ", $to, "\n";
open(SOURCE, "<$from"); # open the input file
open(OUT, ">$to"); # open the output file
while () {
chomp; # remove newline at end of input line
# print the line number, a space and then the input line
# # print the line number, a space and then the input line
print OUT $count . " " . $_ . "\n";
$count += 10; # increment line count
}

close SOURCE;
close OUT;

The command line and output looks like:

--> ./number.pl comics
From comics.txt to comics2.txt

The code snippet from above looks like this after the line numbers are added

915 rem CREATE A NUMBERPICKER FOR CHOOSING PRICES AND WHICH BOX THE COMICS
925 rem ARE IN. ORIGINALLY, THE PRICES WERE A SOUP BASED LIST, BUT AFTER
935 rem TRYING IT, A NUMBERPICKER SEEMED EASIER.
945 makelabels: rem CREATE LABEL PICKERS
955 pricespec := {text:"Price",minvalue:-1,maxvalue:10000,value:0}
965 pricespec.showleadingzeros=nil
975 pricespec.viewbounds = setbounds(52,260,200,290)
985 window wins[0],pricespec,"numberpicker"
995 rem
1005 boxspec := {text:"Box",gosub:'boxchosen}
1015 boxspec.viewbounds = setbounds(221,296,299,316)
1025 boxspec.labelcommands = [""] // ADD LIST OF BOXES LATER
1035 window wins[1],boxspec,"labelpicker"
1045 return // END OF makelabels

Converting to a Newton Book

The simplest way to get the file downloaded to the Newton and into NS BASIC is to first make a book out of it. Sounds weird, but NS BASIC has a command to read BASIC programs from Newton Books. I used NewtonPress, mostly because I had it. The start up page looks like: NewtonPress startup screen 

Click on the Add button. Browse around until you find the file you created above. In this case, it is comics2.txt. If the program asks you to substitute a font, pick anything you like, it won't matter. After this, the screen will look like: NewtonPress after adding 

Now that the book is loaded, click on Create and this dialog box shows up:

NewtonPress Create Dialog

If you are happy with the name, just click Save. The last step is to run 'Install Package' under the File menu. Select the package you just created and this display appears:

NewtonPress Install Dialog

If you have a terminal connection to the Newton, you will have to disconnect. It can't support that link and download the package at the same time.

Digression on Newton and fast computers

Slowdown program

There is a problem connecting to the Newton from faster computers. In my case here, faster means 1.8GHZ. Often, the connection, using NCU, Newton Press or the Newton Tool Kit, will get dropped or never connect in the first place. A solution is the program slowdown. There is an article about this on WikiWikiNewt. The slowdown program is available on UNNA. I find that one copy of slowdown running is enough. I set both sliders about 1/2 way before making the connection. After the connection is made, it seems to be OK to slide them back to about 1/3, which makes the PC more responsive. End of digression.


Follow the directions and you should see a progress meter telling you the package is being installed. Note that if you already have a package by the same name on the same store, the install will fail. This is likely to happen since when you make changes to the source file, you will probably create the same package again. NewtonPress asks if you want to overwrite the old one when you click on Create but the download will fail. Remember to delete the old one on the Newton before downloading a new one.

Loading into NS BASIC

Start up NS BASIC. When NSBasic starts, a keyboard is present.

NS Basic Startup Screen

To use the PC keyboard via the terminal emulator, you have to close the keyboard on the Newt. Now you can see some controls

. NS Basic Controls

NS Basic Use Screen List

Select the Use Screen button and you will see this list. change the connection to use the external serial. Now you can connect a terminal emulator to the Newton. The steps below can also be done directly on Newt using either the on screen keyboard or a Newton keyboard.

In these pictures I am using the on screen keyboard, but the results are the same if you are using a terminal emulator. At the prompt, type 'NEW' to clear the memory of the old version. Then type ENTER "comics2" or whatever the package name is. The double quotes are needed. In the terminal session, you will see the prompt come back. But on the Newton, you will see a progress meter as it loads the program. For the comics program, which is about 800 lines, this takes more than 10 minutes.

NS Basic Enter Command

After the loading is done, you should check if it worked. If I have a syntax error in the code, it stops loading at that point but doesn't tell me anything helpful. So I list the last few lines to see if they are there. If they aren't, I have to list the whole program and see where it stopped.