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

Top Mobile Game Discounts
Every day, we pick out a curated list of the best mobile discounts on the App Store and post them here. This list won't be comprehensive, but it every game on it is recommended. Feel free to check out the coverage we did on them in the links... | Read more »
Price of Glory unleashes its 1.4 Alpha u...
As much as we all probably dislike Maths as a subject, we do have to hand it to geometry for giving us the good old Hexgrid, home of some of the best strategy games. One such example, Price of Glory, has dropped its 1.4 Alpha update, stocked full... | Read more »
The SLC 2025 kicks off this month to cro...
Ever since the Solo Leveling: Arise Championship 2025 was announced, I have been looking forward to it. The promotional clip they released a month or two back showed crowds going absolutely nuts for the previous competitions, so imagine the... | Read more »
Dive into some early Magicpunk fun as Cr...
Excellent news for fans of steampunk and magic; the Precursor Test for Magicpunk MMORPG Crystal of Atlan opens today. This rather fancy way of saying beta test will remain open until March 5th and is available for PC - boo - and Android devices -... | Read more »
Prepare to get your mind melted as Evang...
If you are a fan of sci-fi shooters and incredibly weird, mind-bending anime series, then you are in for a treat, as Goddess of Victory: Nikke is gearing up for its second collaboration with Evangelion. We were also treated to an upcoming... | Read more »
Square Enix gives with one hand and slap...
We have something of a mixed bag coming over from Square Enix HQ today. Two of their mobile games are revelling in life with new events keeping them alive, whilst another has been thrown onto the ever-growing discard pile Square is building. I... | Read more »
Let the world burn as you have some fest...
It is time to leave the world burning once again as you take a much-needed break from that whole “hero” lark and enjoy some celebrations in Genshin Impact. Version 5.4, Moonlight Amidst Dreams, will see you in Inazuma to attend the Mikawa Flower... | Read more »
Full Moon Over the Abyssal Sea lands on...
Aether Gazer has announced its latest major update, and it is one of the loveliest event names I have ever heard. Full Moon Over the Abyssal Sea is an amazing name, and it comes loaded with two side stories, a new S-grade Modifier, and some fancy... | Read more »
Open your own eatery for all the forest...
Very important question; when you read the title Zoo Restaurant, do you also immediately think of running a restaurant in which you cook Zoo animals as the course? I will just assume yes. Anyway, come June 23rd we will all be able to start up our... | Read more »
Crystal of Atlan opens registration for...
Nuverse was prominently featured in the last month for all the wrong reasons with the USA TikTok debacle, but now it is putting all that behind it and preparing for the Crystal of Atlan beta test. Taking place between February 18th and March 5th,... | Read more »

Price Scanner via MacPrices.net

AT&T is offering a 65% discount on the ne...
AT&T is offering the new iPhone 16e for up to 65% off their monthly finance fee with 36-months of service. No trade-in is required. Discount is applied via monthly bill credits over the 36 month... Read more
Use this code to get a free iPhone 13 at Visi...
For a limited time, use code SWEETDEAL to get a free 128GB iPhone 13 Visible, Verizon’s low-cost wireless cell service, Visible. Deal is valid when you purchase the Visible+ annual plan. Free... Read more
M4 Mac minis on sale for $50-$80 off MSRP at...
B&H Photo has M4 Mac minis in stock and on sale right now for $50 to $80 off Apple’s MSRP, each including free 1-2 day shipping to most US addresses: – M4 Mac mini (16GB/256GB): $549, $50 off... Read more
Buy an iPhone 16 at Boost Mobile and get one...
Boost Mobile, an MVNO using AT&T and T-Mobile’s networks, is offering one year of free Unlimited service with the purchase of any iPhone 16. Purchase the iPhone at standard MSRP, and then choose... Read more
Get an iPhone 15 for only $299 at Boost Mobil...
Boost Mobile, an MVNO using AT&T and T-Mobile’s networks, is offering the 128GB iPhone 15 for $299.99 including service with their Unlimited Premium plan (50GB of premium data, $60/month), or $20... Read more
Unreal Mobile is offering $100 off any new iP...
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, 14, 13, and SE... Read more
Apple drops prices on clearance iPhone 14 mod...
With today’s introduction of the new iPhone 16e, Apple has discontinued the iPhone 14, 14 Pro, and SE. In response, Apple has dropped prices on unlocked, Certified Refurbished, iPhone 14 models to a... Read more
B&H has 16-inch M4 Max MacBook Pros on sa...
B&H Photo is offering a $360-$410 discount on new 16-inch MacBook Pros with M4 Max CPUs right now. B&H offers free 1-2 day shipping to most US addresses: – 16″ M4 Max MacBook Pro (36GB/1TB/... Read more
Amazon is offering a $100 discount on the M4...
Amazon has the M4 Pro Mac mini discounted $100 off MSRP right now. Shipping is free. Their price is the lowest currently available for this popular mini: – Mac mini M4 Pro (24GB/512GB): $1299, $100... Read more
B&H continues to offer $150-$220 discount...
B&H Photo has 14-inch M4 MacBook Pros on sale for $150-$220 off MSRP. B&H offers free 1-2 day shipping to most US addresses: – 14″ M4 MacBook Pro (16GB/512GB): $1449, $150 off MSRP – 14″ M4... Read more

Jobs Board

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