TweetFollow Us on Twitter

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 especially 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 *
GOSUB "Openfile"
OV=False 
OH=True 
Softscroll=False : REM ** Softscroll = Soft-Scroll Flag **
SCROLL BUTTON 1,OV,OV,TL-1,TL/10,,1 
SCROLL BUTTON 2,OH,OH,255,10,,2
ON DIALOG GOSUB "Dialog"
ON MENU GOSUB "MenuEvent"
WINDOW#1,A$ : REM *** File name to Title ***
DIALOG ON
MENU ON
BREAK ON : REM **0=Normal Scroll 1=Soft Scroll **
"Loop"    : GOTO "Loop" : REM  Main Event Trapping Loop

DIALOG OFF: BREAK OFF :MENU OFF
REM *** Turn OFF dialogs for rest of PGM ***
"MenuEvent"
Menunumber = MENU(0)
Menuitem = MENU(1)
LONG IF Menunumber = 1 
IF Menuitem = 1 THEN GOSUB "Openfile"
IF Menuitem = 3 THEN STOP
END IF
IF Menuitem = 1 THEN Softscroll = 0 ELSE Softscroll = 1
MENU
RETURN

"Dialog"  : D=DIALOG(0) : REM  Dialog Events here.. 
ON D GOTO "Button","X","ACTIVE","GoAway","Update","X","X","Zoom","Zoom"
"ACTIVE"
WINDOW #DIALOG(D) 
RETURN : REM ** Activate this Window **
"Button"
IF DIALOG(D)=1 THEN Buttonvalue=BUTTON(1)  ELSE "Side"
X=OV-Buttonvalue
IF ABS(X) > SL THEN OV=Buttonvalue : CLS : GOTO "Update"
IF X>0 THEN DV=Height :DL=-1 : Leading=0 : P=Ascent ELSE       DV=-Height 
:DL=+1 :Leading=SL+1 :  P=(SL-1)*Height+Ascent
WHILE OV<>Buttonvalue
IF Softscroll THEN DV=SGN(DV) : II=1 ELSE II=Height
FOR II=II TO Height 
SCROLL (0,0)-(W6,W7),,DV : REM  SCROLL 1 line or 1 Pixel
PRINT %(-BUTTON(2)*WidMax, P+(DV*(II-Height)));    INDEX$(OV-1+Leading);
NEXT 
OV=OV+DL : REM  Remove NEXT if soft-scroll not used
WEND   : RETURN
"Zoom" 
CLS : RETURN : REM  ERASE IF ZOOM-IN OR ZOOM OUT
"Side" 
SCROLL(0,0)-(W6,W7),(OH-BUTTON(2))*WidMax,0:OH=BUTTON(2)
"Update"
W6=WINDOW(6)-1 : W7=WINDOW(7)-1 : SL=W7/Height
FOR II= OV TO OV+SL-1 : REM  Re-Draw Full Screen 
PRINT %(-BUTTON(2)*WidMax, (II-OV)*Height+Ascent);INDEX$(II);
NEXT
COLOR 0 :BOX FILL 0,SL*Height TO W6,W7 :COLOR -1
REM *Erase Bottom*
"X" 
RETURN : REM  **** Just RETURN routine ****
"GoAway"
STOP
"Openfile" : A$=FILES$(1,"TEXT",,V%) 
IF A$="" THEN BEEP : STOP ELSE CLS
OPEN "I",#1,A$,1,V% 
CLEAR LOF(1)+32
TL=0 
IF MEM=0 THEN STOP
WHILE NOT EOF(1)
REM ****> Read TEXT file into INDEX$ array <*****
LINEINPUT#1,W$
INDEX$(TL)=W$ 
TL=TL+1 : REM FILL INDEX$ FROM FILE
WEND 
CLOSE 
RETURN
REM ****************************************************
REM ** Some Possible Changes: 
REM ** Line 210 Change 'ABS(X) > SL' to 'ABS(X) > 1' Single REM      
  Line Soft    
REM ** Add 'CLEAR 0' to Erase INDEX$ Array When Text 
REM         Window Closed. 
REM **********************************************************


REM ********* INDEX Scroll Bar(s) Demo
REM *** ZBasic 3.05 or Greater
REM *** by D. Kelly  MacTutor™  April 1987
REM****************************************
WINDOW OFF
COORDINATE WINDOW
DIM ST(30,1)
CLEAR 11000
TL = 0
WIDTH -2
False = 0 : True = NOT False
X=MEM(-1) :REM *** Disable Line Wrap
WINDOW 1,"INDEX / SCROLL Demo",(50,50)-(450,255),9
REM  ** Initial Window Size **
TEXT 4,9
MENU 1,0,1,"File"
MENU 1,1,1,"Quit"
MENU 2,0,1,"Scroll Type"
MENU 2,1,1,"Normal Scroll"
MENU 2,2,1,"Soft Scroll"
MENU 3,0,1,"INDEX Demo"
MENU 3,1,1,"Add Record/A"
MENU 3,2,1,"Insert Record/I"
MENU 3,3,1,"Edit Record/E"
MENU 3,4,1,"Find Record/F"
MENU 3,5,1,"Delete Record/D"
DIM Ascent,Descent,WidMax,Leading
CALL GETFONTINFO(Ascent)
Height=Ascent+Descent+Leading :REM * Font Size *
OV=False 
OH=True 
Softscroll=False : REM  Softscroll = Soft-Scroll Flag 
SCROLL BUTTON 1,OV,OV,TL-1,TL/10,,1 
SCROLL BUTTON 2,OH,OH,255,10,,2
ON DIALOG GOSUB "Dialog"
ON MENU GOSUB "MenuEvent"
DIALOG ON
MENU ON
BREAK ON : REM 0=Normal Scroll 1=Soft Scroll 
"Loop"    : GOTO "Loop" : REM  Main Event Loop

DIALOG OFF: BREAK OFF :MENU OFF
REM  Turn OFF dialogs for rest of PGM
"MenuEvent"
Menunumber = MENU(0)
Menuitem = MENU(1)
ON Menunumber GOSUB "File","Scroll","Index"
MENU
RETURN

"File"
IF Menunumber = 1 THEN STOP
RETURN
"Scroll"
IF Menuitem = 1 THEN Softscroll = 0 ELSE Softscroll = 1
RETURN
"Index"
ON Menuitem GOSUB "Add","Insert","Change","Find","Delete"
RETURN
"Dialog"  : D=DIALOG(0) : REM Dialog come here.. 
ON D GOTO "Button", "X", "Active", "GoAway", "Update", "X", "X", 
 "Zoom", "Zoom"
"Active"
WINDOW #DIALOG(D) 
RETURN : REM ** Activate this Window **
"Button"
IF DIALOG(D)=1 THEN Buttonvalue=BUTTON(1)  ELSE "Side"
X=OV-Buttonvalue
IF ABS(X) > SL THEN OV=Buttonvalue : CLS : GOTO "Update"
IF X>0 THEN DV=Height :DL=-1 :Leading=0 :P=Ascent ELSE 
 DV=-Height :DL=+1 :Leading=SL+1 : P=(SL-1)*Height+Ascent
WHILE OV<>Buttonvalue
IF Softscroll THEN DV=SGN(DV) : II=1 ELSE II=Height
FOR II=II TO Height 
SCROLL (0,0)-(W6,W7),,DV : REM SCROLL 1 line or 1 Pixel
PRINT %(-BUTTON(2)*WidMax, P+(DV*(II-Height)));    INDEX$(OV-1+Leading);
NEXT 
OV=OV+DL : REM Remove NEXT if soft-scroll not used 
WEND   : RETURN
"Zoom" 
CLS : RETURN : REM  ERASE IF ZOOM-IN OR ZOOM OUT
"Side" 
SCROLL(0,0)-(W6,W7),(OH-BUTTON(2))*WidMax,0:OH=BUTTON(2)
"Update"
W6=WINDOW(6)-1 : W7=WINDOW(7)-1 : SL=W7/Height
FOR II= OV TO OV+SL-1 : REM Re-Draw Full Screen 
PRINT %(-BUTTON(2)*WidMax, (II-OV)*Height+Ascent);INDEX$(II);
NEXT
COLOR 0 :BOX FILL 0,SL*Height TO W6,W7 :COLOR -1
REM *Erase Bottom*
"X" 
RETURN : REM  **** Just RETURN routine ****
"GoAway"
WINDOW CLOSE DIALOG(4):RETURN
"Insert"
WINDOW 2,"Insert",(100,100)-(400,200),-263
TEXT 2,0 : LOCATE 1,2
INPUT "Insert record before #:";N
IF N<0 THEN N=0
IF N>TL THEN N=TL
INPUT "Insert record: ";W$
INDEX$I (N) = W$
TL = TL + 1
WINDOW CLOSE 2
WINDOW 1
SCROLL BUTTON 1,OV,OV,TL-1,TL/10,,1
CLS:GOSUB "Update"
RETURN
"Add"
WINDOW 2,"Insert",(100,100)-(400,200),-263
TEXT 2,0 : LOCATE 1,2
INPUT "Add record: ";W$
INDEX$ (TL) = W$
TL = TL + 1
WINDOW CLOSE 2
WINDOW 1
SCROLL BUTTON 1,OV,OV,TL-1,TL/10,,1
RETURN
"Delete"
WINDOW 2,"Delete",(100,100)-(400,200),-263
TEXT 2,0 : LOCATE 1,2
INPUT "Record number to delete: (<0 to abort)";N
IF N>=0 THEN INDEX$D(N) : TL = TL - 1
WINDOW CLOSE 2
SCROLL BUTTON 1,OV,OV,TL-1,TL/10,,1
WINDOW 1
CLS:GOSUB "Update"
RETURN
"Change"
WINDOW 2,"Change",(100,100)-(400,200),-263
TEXT 2,0 : LOCATE 1,2
INPUT "Record number to Change: (<0 to abort)";N
PRINT "Current record is ";INDEX$(N)
INPUT "Change record to:";W$
IF W$ = "" THEN W$ = INDEX$(N)
INDEX$(N) = W$
WINDOW CLOSE 2
WINDOW 1
CLS:GOSUB "Update"
RETURN
"Find"
WINDOW 2,"Find",(100,100)-(400,200),-263
TEXT 2,0 : LOCATE 1,2
INPUT "Record string to Find:";W$
OV=INDEXF(W$)
WINDOW CLOSE 2
WINDOW 1
SCROLL BUTTON 1,OV,OV,TL-1,TL/10,,1
CLS:GOSUB "Update"
RETURN

There is some new news on the BASIC WARS scene. Pterodactyl Software is back to work on the PCMacBasic compiler. Version 1.96 is out and a new manual. Most of the improvements are in reliability. Functionally it appears to be the same BASIC as before, but with less problems with HFS. It now finds all of the necessary files no matter where they are located. PCMacBasic still has good potential as it is the only BASIC that will interface with MDS and MPW. MPW support is coming very soon. Most of my comments from my previous reviews still hold except for what I have mentioned here.

Stay in touch for more info on products for BASIC. Currently ZBasic is at version 3.05, True Basic is at 1.1 (still), Softworks Basic (no change), MS Basic interpreter 3.0, MS Basic Compiler 1.0, PCMacBasic 1.96.

Any questions, just drop me a note care of MacTutor. I'm trying to answer some of your questions now. Please be patient because some of the questions you have asked involve changes that Zedcor is making as they constantly improve ZBasic. DIALOG statements which I commented on in the January 1987 MacTutor do not work properly in versions before 3.05. If you compile the programs in this month's issue with anything earlier than 3.05 you will see that there are problems with those earlier versions. It has been extremely difficult to work with a product which has evolved so rapidly. When troubleshooting programs I have written, it has been a challenge to determine if the problems were caused by bugs in the compiler or bugs in my source code. Check your own code first, then if you're pretty sure your code is ok you can start blaming the compiler. I've found times when both the compiler and the source code (my source code) was at fault. Please write if you are experiencing some difficulties.

 

Community Search:
MacTech Search:

Software Updates via MacUpdate

How to get started with live.ly
One could be forgiven for thinking that there are already plenty of streaming video apps out there. It's just that the App Store charts would insist that you're mistaken. [Read more] | Read more »
Rodeo Stampede: Guide to all Savannah an...
A "gotta catch 'em all" joke seems appropriate here, even though we're talking animals in Rodeo Stampede and not pocket monsters. By now you've probably had plenty of rides, tamed some animals and built yourself a pretty nice zoo | Read more »
Is there cross-platform play in slither....
So you've sunken plenty of hours into crawling around in slither.io on your iPhone or iPad. You've got your stories of tragedy and triumph, the times you coiled four snakes at one time balanced out by the others when you had a length of more than... | Read more »
Rodeo Stampede guide to running a better...
In Rodeo Stampede, honing your skills so you can jump from animal to animal and outrun the herd as long as possible is only half the fun. Once you've tamed a few animals, you can bring them home with you. [Read more] | Read more »
VoxSyn (Music)
VoxSyn 1.0 Device: iOS Universal Category: Music Price: $6.99, Version: 1.0 (iTunes) Description: VoxSyn turns your voice into the most flexible vocal sound generator ever. Instantly following even subtle modulations of pitch and... | Read more »
Catch Battleplans on Google Play from Ju...
Real-time strategy title Battleplans is due for release on Google Play on June 30th, following its release for iOS systems last month. With its simple interface and pretty graphics, the crowd-pleaser brings a formerly overlooked genre out for the... | Read more »
iDoyle: The interactive Adventures of Sh...
iDoyle: The interactive Adventures of Sherlock Holmes - A Scandal in Bohemia 1.0 Device: iOS Universal Category: Books Price: $1.99, Version: 1.0 (iTunes) Description: Special Release Price $1.99 (Normally $3.99) | Read more »
Five popular free apps to help you slim...
Thanks to retail and advertising, we're used to thinking one season ahead. Here we are just a week into the summer and we're conditioned to start thinking about the fall. [Read more] | Read more »
How to ride longer and tame more animals...
It's hard to accurately describe Rodeo Stampede to people who haven't seen it yet. It's like if someone took Crossy Roadand Disco Zoo and put them in a blender, yet with a unique game mechanic that's still simple and fun for anyone. [Read more] | Read more »
Teeny Titans - A Teen Titans Go! Figure...
Teeny Titans - A Teen Titans Go! Figure Battling Game 1.0.0 Device: iOS Universal Category: Games Price: $3.99, Version: 1.0.0 (iTunes) Description: Teeny Titans, GO! Join Robin for a figure battling RPG of epic proportions! TEENY... | Read more »

Price Scanner via MacPrices.net

MacBook Airs on sale for up to $50-$100 off M...
B&H Photo has 13″ and 11″ MacBook Airs on sale for up to $100 off MSRP. Shipping is free, and B&H charges NY sales tax only: - 11″ 1.6GHz/128GB MacBook Air: $849 $50 off list price - 11″ 1.... Read more
Brexit Vote Result Forecast To Slash UK 2016...
Uncertainty and economic volatility can be expected to increase over the next nine months, as the Brexit and concerns over the future of the EU hit IT investment, say Canalys market analysts, with... Read more
13-inch 256GB MacBook Air on sale for $1149,...
Amazon has the 2016 13″ 1.6GHz/256GB MacBook Air (model MMGG2LL/A) on sale for $1149.99 including free shipping. Their price is also $50 off MSRP. Read more
Haven App Launches New Age Of Wirless 911 Eme...
Haven from RapidSOS represents a transformation in access to emergency services from a phone call solely dependent on voice to a robust data connection for voice, text, medical/demographic data.... Read more
Cu Parachute 1.1 Retirement Success PLanning...
Tucson, Arizona based Indie developer Bradley McCarthy has announce the release of Cu (Copper) Parachute 1.1 for iPhone, iPad, and iPod touch devices — a tool with which users can continuously... Read more
Research and Markets Releases iPhone 6s Plus...
A new analysis report from Dublin-based Research and Markets observes that with the iPhone 6s Plus, Apple introduced a new rear camera module. The new device has similar structure and technology than... Read more
Apple refurbished Retina MacBook Pros availab...
Apple has Certified Refurbished 2015 13″ and 15″ Retina MacBook Pros available for up to $380 off the cost of new models. An Apple one-year warranty is included with each model, and shipping is free... Read more
Apple refurbished 11-inch MacBook Airs availa...
Apple has Certified Refurbished 11″ MacBook Airs (the latest models), available for up to $170 off the cost of new models. An Apple one-year warranty is included with each MacBook, and shipping is... Read more
Apple price trackers, updated continuously
Scan our Apple Price Trackers for the latest information on sales, bundles, and availability on systems from Apple’s authorized internet/catalog resellers. We update the trackers continuously: - 15″... Read more
12-inch 32GB and 128GB WiFi iPad Pros on sale...
B&H Photo has 12″ 32GB & 128GB WiFi iPad Pros on sale for up to $80 off MSRP, each including free shipping. B&H charges sales tax in NY only: - 12″ Space Gray 32GB WiFi iPad Pro: $749 $50... Read more

Jobs Board

*Apple* iPhone 6s and New Products Tester Ne...
…we therefore look forward to put out products to quality test for durability. Apple leads the digital music revolution with its iPods and iTunes online store, Read more
*Apple* iPhone 6s and New Products Tester Ne...
…we therefore look forward to put out products to quality test for durability. Apple leads the digital music revolution with its iPods and iTunes online store, Read more
*Apple* iPhone 6s and New Products Tester Ne...
…we therefore look forward to put out products to quality test for durability. Apple leads the digital music revolution with its iPods and iTunes online store, Read more
*Apple* Retail - Multiple Positions, Towson...
Job Description: Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, Read more
*Apple* iPhone 6s and New Products Tester Ne...
…we therefore look forward to put out products to quality test for durability. Apple leads the digital music revolution with its iPods and iTunes online store, Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.