Scrolling ZBASIC
Volume Number: 3
Issue Number: 4
Column Tag: Basic School
Scrolling in ZBASIC 
By Dave Kelly, MacTutor Editorial Board
ZBASIC SCROLLING
Thus far it has not been made widely known what or how the ZBasic Scroll
Buttons could be used. Of course, they return a value relating to the position of the
scroll bar, but until now how to use the scroll bar for scrolling text has eluded me.
Part of the problem comes when reading in the ZBasic manual which states "SCROLLing
windows with Buttons or Scroll bars will cause interesting AND unpredictable
results." (pg. D-56). This implies to me that SCROLLing is not meant to be used with
Scroll bars. However, after questioning Zedcor about this, they sent me a demo scroll
program which does just that, scrolling with Scroll bars. There is a requirement
however. The routine doesn't quite work right without version 3.05 or greater.
Earlier versions of ZBasic don't clear the screen and update properly. [In particular,
the current official version 3.03, when doing a slow scroll, begins mashing the bottom
window frame to a nice black mush. The next official release is due April 2nd. A new
manual is also being prepared. -Ed] Hopefully, by the time you are reading this you
have already upgraded to version 3.05 or greater. Zedcor really has been very good at
updating those people who have already purchased ZBasic. You should know that they
want $19.95 to upgrade if you have had your copy for 60 days or more. Most of the
upgrades have included significant improvements which should have worked to begin
with (those upgrades should be free!). Most improvements have been bug fixes. I'm
looking forward to the much needed editor that will soon be included in a future
upgrade. Zedcor promises to soon release an editor that will highlight keywords in
bold face similar to the MS BASIC editor.
Well, back to SCROLLing. The Zedcor demo program demonstrates to us how we
can use Scroll bars and the SCROLL statement to scroll text. The SCROLL statement
allows you to scroll a selected area of a window. Although the concept of how the
scrolling works is simple, the implementation is somehow complex. The thing that
makes it seem complex is the many variables that are required to keep track of how
much the window needs to be scrolled and which line of text should be displayed at the
top of the screen. If you take time to study out the routine you can easily adapt it for
use in your own programs.
The Scroll bars in ZBasic are set up by using the SCROLL BUTTON statement. A
SCROLL BUTTON is a control which works much like other buttons in that when ON
DIALOG is used to trap events the BUTTON (button number) function will return the
value of the SCROLL bar's position. The syntax for the SCROLL BUTTON is:
SCROLL BUTTON [#] button number, current value [[, min value], max
value][,[page up/down][, (x1,y1)- (x2,y2)] [, type]]].
The unfortunate thing about the ZBasic Scroll bars is that there is no provision
for scrolling the text being edited in an EDIT FIELD statement. (Up to now, none of the
versions of BASIC have provided a way to do this, except the still undocumented
statements for text edit in version 3.0 of MS BASIC). The alternative is to use the
toolbox statements (which are not yet proven to be reliable) to access the text edit
routines in the ROMs. This would still require some manipulation to use the Scroll
bars with the ROM text edit routines. It would be nice to have routines which
automatically link text edit capabilities with the scrolling. Even some routines that
linked scroll bars and text edit half way would be a help. For reference, take a look at
the January 1986 issue of MacTutor. In that article I show examples of using CLR
Libraries for scrolling text. (These libraries are now included with version 3.0 of MS
BASIC and also with the MS BASIC Compiler). The CLR Libraries statements make
using Scroll bars easier, but even these are limited. ZBasic's scroll bars may be
considered as totally independent of other functions or statements. CLR Libraries are
easier to implement (but they don't work with ZBasic).
There are two kinds of scrolling demonstrated by Zedcor's demo program.
SoftScrolling is done by scrolling the text by one pixel at a time. Normal scrolling
will scroll one line at a time. The line height is calculated by getting font information
via the GETFONTINFO toolbox call. For most text applications the normal scrolling is
more appropriate. Softscrolling is somewhat slow because it takes more steps to
scroll one pixel at a time than to scroll a whole line.
Z-INDEX Scrolling
ZBasic has provided BASIC programmers with some unique statements not found
in other versions of BASIC. We will discuss one of these now in order to familiarize
ourselves with it. The INDEX$ statement provides users with an automatic way to
insert, delete, edit and find data stored in an array.
The Macintosh version of ZBasic allows ten INDEX$ arrays to be active (only one
INDEX$ array in other versions). The array looks and feels much like any other array
that you may decide to use except that there are special statements to enhance array
manipulation. The first thing that is done when using INDEX$ statements is to set up
some memory which can be used for the arrays. This is accomplished with the CLEAR
nnnnnnn [,index#] statement, where index# is the number of the INDEX$ array to be
used. You may consider this as a multi-dimension array except that the second
dimension range is from 0 to 9. You may use the MEM [(index#)] to determine the
total memory available. ZBasic allows you to insert, replace, delete and find data with
the following statements:
INDEX$ (element# [,index#]) = string : use to set an array element to a string.
INDEX$I (element# [,index#]) = string : use to insert a string at element#.
The array contents in elements equal to or greater than element# are moved to the
next higher element# to make room for the new element.
INDEX$D (element# [,index#]) = string : use to delete a string at element#.
The array contents in elements equal to or greater than element# are moved down to
the next lower element#.
Clearly these are valuable statements e specially when inserting data into a file or
into a proper order. The example program demonstrates the use of INDEX$ to insert
data into a list. The scroll demo has been integrated into the program to scroll through
the list. Also the INDEXF statement is used to search for a set string and the program
lists the remainder of the list starting with the value searched for. To reset to all
records, just find the first record again. There could be much more refinement to the
program I'll leave that up to you. The programs are sufficient examples to get you
started. One problem I ran into while working with the INDEX-SCROLL example is that
I forgot to access the first window after closing the second window (which was used for
input). By simply using the WINDOW #1 statement the output will then go to the first
window for subsequent statements. If you don't do this you may get a bomb because you
closed the window you specified for printing, but didn't respecify a new window. There
are a few other subtle things that may affect the way your program works. The Zedcor
example uses GOTO occasionally. I try to stay away from this one whenever I can, but
since the Zedcor routine works, why re-invent the wheel. You may want to change all
GOTOs to GOSUBs to be consistent with the structured programming approach. I
modified some of the GOTOs already so there are fewer than there used to be.
REM *********** Text Window Scroll Bar(s) Example
REM ZBasic 3.05 or Greater 1/87 A.G ZEDCOR, INC.
REM with modifications & explainations 2/87
REM by D. Kelly MacTutorâ„¢
REM *************************************************
WINDOW OFF
COORDINATE WINDOW
WIDTH -2
False = 0 : True = NOT False
X=MEM(-1) :REM *** Disable Line Wrap ***
WINDOW 1,"Untitled",(50,50)-(450,255),9
REM ** Initial Window Size **
TEXT 4,9
MENU 1,0,1,"File
MENU 1,1,1,"Open
MENU 1,2,0,"-
MENU 1,3,1,"Quit
MENU 2,0,1,"Scroll Type
MENU 2,1,1,"Normal Scroll
MENU 2,2,1,"Soft Scroll
DIM Ascent,Descent,WidMax,Leading
CALL GETFONTINFO(Ascent)
Height=Ascent+Descent+Leading :REM * Font Size *