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

Latest Forum Discussions

See All

Combo Quest (Games)
Combo Quest 1.0 Device: iOS Universal Category: Games Price: $.99, Version: 1.0 (iTunes) Description: Combo Quest is an epic, time tap role-playing adventure. In this unique masterpiece, you are a knight on a heroic quest to retrieve... | Read more »
Hero Emblems (Games)
Hero Emblems 1.0 Device: iOS Universal Category: Games Price: $2.99, Version: 1.0 (iTunes) Description: ** 25% OFF for a limited time to celebrate the release ** ** Note for iPhone 6 user: If it doesn't run fullscreen on your device... | Read more »
Puzzle Blitz (Games)
Puzzle Blitz 1.0 Device: iOS Universal Category: Games Price: $1.99, Version: 1.0 (iTunes) Description: Puzzle Blitz is a frantic puzzle solving race against the clock! Solve as many puzzles as you can, before time runs out! You have... | Read more »
Sky Patrol (Games)
Sky Patrol 1.0.1 Device: iOS Universal Category: Games Price: $1.99, Version: 1.0.1 (iTunes) Description: 'Strategic Twist On The Classic Shooter Genre' - Indie Game Mag... | Read more »
The Princess Bride - The Official Game...
The Princess Bride - The Official Game 1.1 Device: iOS Universal Category: Games Price: $3.99, Version: 1.1 (iTunes) Description: An epic game based on the beloved classic movie? Inconceivable! Play the world of The Princess Bride... | Read more »
Frozen Synapse (Games)
Frozen Synapse 1.0 Device: iOS iPhone Category: Games Price: $2.99, Version: 1.0 (iTunes) Description: Frozen Synapse is a multi-award-winning tactical game. (Full cross-play with desktop and tablet versions) 9/10 Edge 9/10 Eurogamer... | Read more »
Space Marshals (Games)
Space Marshals 1.0.1 Device: iOS Universal Category: Games Price: $4.99, Version: 1.0.1 (iTunes) Description: ### IMPORTANT ### Please note that iPhone 4 is not supported. Space Marshals is a Sci-fi Wild West adventure taking place... | Read more »
Battle Slimes (Games)
Battle Slimes 1.0 Device: iOS Universal Category: Games Price: $1.99, Version: 1.0 (iTunes) Description: BATTLE SLIMES is a fun local multiplayer game. Control speedy & bouncy slime blobs as you compete with friends and family.... | Read more »
Spectrum - 3D Avenue (Games)
Spectrum - 3D Avenue 1.0 Device: iOS Universal Category: Games Price: $2.99, Version: 1.0 (iTunes) Description: "Spectrum is a pretty cool take on twitchy/reaction-based gameplay with enough complexity and style to stand out from the... | Read more »
Drop Wizard (Games)
Drop Wizard 1.0 Device: iOS Universal Category: Games Price: $1.99, Version: 1.0 (iTunes) Description: Bring back the joy of arcade games! Drop Wizard is an action arcade game where you play as Teo, a wizard on a quest to save his... | Read more »

Price Scanner via MacPrices.net

14-inch M4 Pro/M4 Max MacBook Pros on sale th...
Don’t pay full price! Get a new 14″ MacBook Pro with an M4 Pro or M4 Max CPU for up to $320 off Apple’s MSRP this weekend at these retailers…they are the lowest prices available for these MacBook... Read more
Get a 15-inch M4 MacBook Air for $150 off App...
A couple of Apple retailers are offering $150 discounts on new 15″ M4 MacBook Airs this weekend. Prices at these retailers start at $1049: (1): Amazon has new 15″ M4 MacBook Airs on sale for $150 off... Read more
Unreal Mobile is offering a $100 discount on...
Unreal Mobile, an MVNO using AT&T and T-Mobile’s networks, is offering a $100 discount on any new iPhone with service. This includes new iPhone 16 models as well as iPhone 15, 13, and SE phones... Read more
16-inch M4 Pro MacBook Pros on sale for $250-...
Don’t pay full price! Amazon has 16-inch M4 Pro MacBook Pros (Silver or Black colors) on sale right now for up to $300 off Apple’s MSRP. Shipping is free. These are the lowest prices currently... Read more
Get a 14-inch M4 MacBook Pro for up to $240 o...
Amazon is offering a $150-$250 discount on Apple’s 14-inch M4 MacBook Pros right now. Shipping is free. Be sure to select Amazon as the seller, rather than a third-party seller: – 14″ M4 MacBook Pro... Read more
Clearance 14-inch M3 Pro MacBook Pros availab...
B&H Photo has clearance 14″ M3 Pro MacBook Pros (in Black or Silver) on sale for $500 off original MSRP, only $1499. B&H offers free 1-2 day delivery to most US addresses: – 14″ 11-Core M3... Read more
Sams Club is offering a $50 discount on Titan...
Sams Club has Titanium Apple Watch Series 10 models on sale for $50 off Apple’s MSRP. Sams Club Membership required. Note that sale prices are for online orders only, in-store prices may vary. Choose... Read more
Sunday Sale: Apple’s latest 13-inch M4 MacBoo...
Amazon has new 13″ M4 MacBook Airs on sale for $150 off MSRP right now, starting at $849. Sale prices apply to most colors and configurations. Be sure to select Amazon as the seller, rather than a... Read more
Apple’s M4 Mac minis on sale for record-low p...
B&H Photo has M4 and M4 Pro Mac minis in stock and on sale right now for up to $150 off Apple’s MSRP, each including free 1-2 day shipping to most US addresses. Prices start at only $469: – M4... Read more
Week’s Best Deals: 14-inch M4 MacBook Pros fo...
Don’t pay full price! These retailers are offering $200-$250 discounts on new 14-inch M4 MacBook Pros this week…they are the lowest sale prices available for new MacBook Pros: (1): Amazon is offering... Read more

Jobs Board

All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.