TweetFollow Us on Twitter

Dialog Events
Volume Number:3
Issue Number:1
Column Tag:Basic School

Dialog Events in ZBasic

By Dave Kelly

DIALOG MANIA

The word 'mania' as used in the title of this month's Basic column has a kind of dual meaning. My dictionary says that 'mania' means: 1. wild or violent mental disorder 2. an excessive enthusiasm; obsession. I find both definitions express what it is like to program with ZBasic. Many of you have been following the 'Basic Wars' as they have been progressing. MS Basic 3.0 has been announced as of the writing of this column, although I have not seen it yet. This is supposed to be a $25 upgrade. The MS Basic compiler is also supposed to be out, at least Microsoft is marketing it by direct mail. (Note: The MS Basic compiler and version 3.0 of the MS Basic interpreter are two different products, both of which you need to compile programs!) Pterodactyl Software's PCMacBasic has not come back off the drawing board and True Basic is no better off than when I reviewed it back in August. But there has still been some hope. Zedcor has been scrambling to fix bugs in ZBasic and release version 3.02. They are to be commended for their dedication to making their product a success.

Why do I say that both definitions of 'mania' describe programming with ZBasic? The second definition comes to mind first. I'm excited to see the big improvements that have been incorporated into ZBasic. In fact, the BOMB is a much less frequent sight. In fact, the BOMBs that appear from time to time now are more obscure. In fact, some of the BOMBs are 'self inflicted'. In other words, sometimes things that I am not doing correctly turn out to be the problem. But there have been a few problems that demonstrate that not all the problems have been removed from the compiler.

One such example of what I am talking about was brought to my attention by one of our subscribers from Switzerland. He summed up ZBasic nicely when he said "...ZBasic is really a great Basic if only it worked!" He described to me a problem he was having when working with DIALOGs and ZBasic. He stated that he could not "flush the value of the DIALOG(1) function". The answer to his problem turns out to not be too hard, however, it reveals to us some other difficulties that ZBasic has 'built in' to it.

First, the solution to the DIALOG(1) problem is that it is not a problem. It will be helpful to understand how the DIALOG functions operate. The DIALOG function originates with MS Basic. The excitement comes when I see all the enhancements that have been added to the ZBasic implementation of DIALOGs. The purpose of the DIALOG function is to inform us when events (such as BUTTON, EDIT FIELD and WINDOWs) that occur between the DIALOG ON and DIALOG OFF statements.

It is important, when using DIALOG functions, to know when the function data is valid. The DIALOG(0) function is the key to it all. When an event occurs, the DIALOG functions are stored up in a 64 event queue. The ON DIALOG GOSUB statement is supposed to cause an interrupt to occur when some kind of event has happened. I say it is 'supposed to' because when writing the sample program included here I found that some of the items in the queue were not automatically read until another event occurred. Of course the new event was then pushed onto the queue and would not automatically interrupt via ON DIALOG. My solution was to poll the event queue continuously unless it was empty by accessing the DIALOG(0) function. Anyway, ideally the ON DIALOG should notify the program whenever any DIALOG events occur. The are seven events that are common to ZBasic and MS Basic. ZBasic now has 16 DIALOG functions including functions which support the Zoom windows and keyboard events. The DIALOG(0) function will return a number 1-16 (1-7 in MS BASIC) which will indicate to you what kind of event occurred. At the same time, the function that coresponds to the DIALOG(0) result will be updated. The functions ( DIALOG (1-16) ) are ONLY valid just after the DIALOG(0) function returns an event of that type. Otherwise the last event of that type remains on, stored up in the DIALOG functions. The figure shows a flow chart of what happens when DIALOG(0) has an event to be processed. Just remember to poll DIALOG(0) first to find out which of the other functions you will need to poll next.

Figure 2.

Another phenomenon that was observed was that when events are active ( the lines between DIALOG ON, MENU ON, BREAK ON, MOUSE ON and DIALOG OFF, MENU OFF, BREAK OFF, MOUSE OFF) the program seems to run much slower than without events on. I tried to turn off events wherever possible with some increase in speed, but there seems to be some delay between polling the time an event occurs and when it is finally processed. Has anyone done any benchmarks to compare speed when events are turned on? It is a difficult thing to compare as the implementation varies so much from one language to another.

Look out here comes another bug... As it turns out, the DIALOG(8) and DIALOG(9) statements work great. The problem is that Zoom windows still don't work quite right. In ZBasic 3.02 the demo program below will BOMB if Zoom windows are made active. I have set it up to demonstrate how it should work. The PEEK (&28E) AND 128 statement towards the beginning of the program checks to see if the Mac has old 64K ROMS or the new 128K ROMS installed. If the new ROMS are available then the window type should be set to 9 when the windows are created.

The example program outlines the basic flow which you will want to use when you implement your own ZBasic event loops. Notice that Menu events and Dialog events are mixed in the same event loop. This same structure also applies for MS BASIC. Any questions?

REM ZBasic V3.02 Dialog Example
REM ©MacTutor 1987
REM By Dave Kelly

WINDOW OFF:REM Always use this as first line of program to prevent default 
window from being created
COORDINATE WINDOW:REM Set window to  Macintosh coordinate system
False=0:True=NOT False
IF PEEK(&28E) AND 128 THEN Wtype=1 ELSE Wtype=9
Wtype=1:REM  Due to Bugs in ZBasic 3.02 Zoom window will not be used.

MENU 1,0,1,"File"
MENU 1,1,1,"Quit"
DIALOG OFF
WINDOW 1,"Window 1",(10,50)-(250,200),Wtype
TEXT 4,9,0,0
BUTTON 1,1,"Button 1",(20,20)-(100,50)
BUTTON 2,1,"Button 2",(20,60)-(100,90)
WINDOW 2,"Window 2",(275,50)-(500,200),Wtype
TEXT 4,9,0,0
EDIT FIELD 1,"",(10,10)-(100,35),1,1
EDIT FIELD 2,"",(10,40)-(100,65),1,1
WINDOW 3,"Dialog Event (Window #3)", (10,250)-(500,340),28
TEXT 4,9,0,0
ON DIALOG   GOSUB "DialogEvent"
ON BREAK    GOSUB "BreakEvent"
ON MENU GOSUB "MenuEvent"
DIALOG ON:BREAK ON:MENU ON
"Mainloop":DO:D=DIALOG(0)
IF D>0 THEN GOSUB "DEvent"
UNTIL D=0
GOTO "Mainloop"

"MenuEvent"
DIALOG STOP:
Menunumber=MENU(0):Itemnumber=MENU(1)
IF Menunumber=1 AND Itemnumber=1 THEN END
DIALOG ON
RETURN
"BreakEvent"
STOP

"DialogEvent"
D = DIALOG(0):REM check to see what event occured
"DEvent"
DIALOG STOP
Currentwindow = WINDOW(0)
Windowselection = WINDOW(1)
WINDOW OUTPUT 3
IF D = 1 GOSUB "Buttonevent"
IF D = 2 GOSUB "EditEvent"
IF D = 3 GOSUB "InactiveWindow"
IF D = 4 GOSUB "Closebox"
IF D = 5 GOSUB "Refresh"
IF D = 6 GOSUB "Returnkey"
IF D = 7 GOSUB "Tabkey"
IF D = 8 GOSUB "Zoomin"
IF D = 9 GOSUB "Zoomout"
IF D =10 GOSUB "Shifttab"
IF D =11 GOSUB "Clearkey"
IF D =12 GOSUB "LeftArrow"
IF D =13 GOSUB "RightArrow"
IF D =14 GOSUB "UpArrow"
IF D =15 GOSUB "DownArrow"
IF D =16 GOSUB "Keypress"
PRINT @(50,3) "DIALOG(0) :        ";D
PRINT @(50,4) "Active Window #";Currentwindow
PRINT @(50,5) "Output Window #";Windowselection
WINDOW OUTPUT Outwindow:WINDOW Windowselection
DIALOG ON
RETURN

"Buttonevent"
Buttonclicked=DIALOG(1)
Bstatus=BUTTON(Buttonclicked):BUTTON Buttonclicked,3-Bstatus
PRINT@(1,1)   "Button clicked :   ";Buttonclicked
RETURN

"EditEvent":
EditField=DIALOG(2)
PRINT@(1,2)   "Edit Field :       ";EditField
RETURN
"InactiveWindow"
Windowselection=DIALOG(3)
PRINT@(1,3)   "Inactive Window :  ";Windowselection
RETURN
"Closebox":
ClosedWindow=DIALOG(4)
IF ClosedWindow=3 THEN END
PRINT@(1,4)   "Closed Window :    ";ClosedWindow
RETURN
"Refresh":
ErasedWindow=DIALOG(5)
PRINT @(1,5)  "Erased Window :    ";ErasedWindow
RETURN
"Returnkey":
Returnpress=DIALOG(6)
PRINT @(25,1) "Return press :     ";Returnpress
RETURN
"Tabkey":
Tabpress=DIALOG(7)
PRINT @(25,2) "Tab press :        ";Tabpress
RETURN

"Zoomin": REM NEW ROMS ONLY
Zin=DIALOG(8)
WINDOW Zin
PRINT@(1,1) "Thank you for zooming in window";Zin
PRINT @(25,3) "Zoom in window :   ";Zin
RETURN
"Zoomout":
Zout=DIALOG(9)
WINDOW Zout
PRINT@(1,1)"Thank you for zooming out window";Zout
PRINT @(25,4) "Zoom out window :  ";Zout
RETURN
"Shifttab":
CurrentEdit=DIALOG(10)
PRINT @(25,5) "Current Edit Field:";CurrentEdit
RETURN
"Clearkey":
CurrentEdit=DIALOG(11)
PRINT @(25,5) "Current Edit Field:";CurrentEdit
RETURN

"LeftArrow":
CurrentEdit=DIALOG(12)
PRINT @(25,5) "Current Edit Field:";CurrentEdit
RETURN
"RightArrow":
CurrentEdit=DIALOG(13)
PRINT @(25,5) "Current Edit Field:";CurrentEdit
RETURN
"UpArrow":
CurrentEdit=DIALOG(14)
PRINT @(25,5) "Current Edit Field:";CurrentEdit
RETURN
"DownArrow":
CurrentEdit=DIALOG(15)
PRINT @(25,5) "Current Edit Field:";CurrentEdit
RETURN

"Keypress":
ASCIIkey=DIALOG(16)
PRINT @(50,1) "ASCII key pressed :";ASCIIkey;"  "
PRINT @(75,1) " ":PRINT @(75,1) CHR$(ASCIIkey)
RETURN
END
 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Latest Forum Discussions

See All

PUBG Mobile teams up with global phenome...
Since launching in 2019, SpyxFamily has exploded to damn near catastrophic popularity, so it was only a matter of time before a mobile game snapped up a collaboration. Enter PUBG Mobile. Until May 12th, players will be able to collect a host of... | Read more »
Embark into the frozen tundra of certain...
Chucklefish, developers of hit action-adventure sandbox game Starbound and owner of one of the cutest logos in gaming, has released their roguelike deck-builder Wildfrost. Created alongside developers Gaziter and Deadpan Games, Wildfrost will... | Read more »
MoreFun Studios has announced Season 4,...
Tension has escalated in the ever-volatile world of Arena Breakout, as your old pal Randall Fisher and bosses Fred and Perrero continue to lob insults and explosives at each other, bringing us to a new phase of warfare. Season 4, Into The Fog of... | Read more »
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 below... | Read more »
Marvel Future Fight celebrates nine year...
Announced alongside an advertising image I can only assume was aimed squarely at myself with the prominent Deadpool and Odin featured on it, Netmarble has revealed their celebrations for the 9th anniversary of Marvel Future Fight. The Countdown... | Read more »
HoYoFair 2024 prepares to showcase over...
To say Genshin Impact took the world by storm when it was released would be an understatement. However, I think the most surprising part of the launch was just how much further it went than gaming. There have been concerts, art shows, massive... | Read more »
Explore some of BBCs' most iconic s...
Despite your personal opinion on the BBC at a managerial level, it is undeniable that it has overseen some fantastic British shows in the past, and now thanks to a partnership with Roblox, players will be able to interact with some of these... | Read more »
Play Together teams up with Sanrio to br...
I was quite surprised to learn that the massive social network game Play Together had never collaborated with the globally popular Sanrio IP, it seems like the perfect team. Well, this glaring omission has now been rectified, as that instantly... | Read more »
Dark and Darker Mobile gets a new teaser...
Bluehole Studio and KRAFTON have released a new teaser trailer for their upcoming loot extravaganza Dark and Darker Mobile. Alongside this look into the underside of treasure hunting, we have received a few pieces of information about gameplay... | Read more »
DOFUS Touch relaunches on the global sta...
After being a big part of a lot of gamers - or at the very least my - school years with Dofus and Wakfu, Ankama sort of shied away from the global stage a bit before staging a big comeback with Waven last year. Now, the France-based developers are... | Read more »

Price Scanner via MacPrices.net

Sunday Sale: 13-inch M3 MacBook Air for $999,...
Several Apple retailers have the new 13″ MacBook Air with an M3 CPU in stock and on sale today for only $999 in Midnight. These are the lowest prices currently available for new 13″ M3 MacBook Airs... Read more
Multiple Apple retailers are offering 13-inch...
Several Apple retailers have 13″ MacBook Airs with M2 CPUs in stock and on sale this weekend starting at only $849 in Space Gray, Silver, Starlight, and Midnight colors. These are the lowest prices... Read more
Roundup of Verizon’s April Apple iPhone Promo...
Verizon is offering a number of iPhone deals for the month of April. Switch, and open a new of service, and you can qualify for a free iPhone 15 or heavy monthly discounts on other models: – 128GB... Read more
B&H has 16-inch MacBook Pros on sale for...
Apple 16″ MacBook Pros with M3 Pro and M3 Max CPUs are in stock and on sale today for $200-$300 off MSRP at B&H Photo. Their prices are among the lowest currently available for these models. B... Read more
Updated Mac Desktop Price Trackers
Our Apple award-winning Mac desktop price trackers are the best place to look for the lowest prices and latest sales on all the latest computers. Scan our price trackers for the latest information on... Read more
9th-generation iPads on sale for $80 off MSRP...
Best Buy has Apple’s 9th generation 10.2″ WiFi iPads on sale for $80 off MSRP on their online store for a limited time. Prices start at only $249. Sale prices for online orders only, in-store prices... Read more
15-inch M3 MacBook Airs on sale for $100 off...
Best Buy has Apple 15″ MacBook Airs with M3 CPUs on sale for $100 off MSRP on their online store. Prices valid for online orders only, in-store prices may vary. Order online and choose free shipping... Read more
24-inch M3 iMacs now on sale for $150 off MSR...
Amazon is now offering a $150 discount on Apple’s new M3-powered 24″ iMacs. Prices start at $1149 for models with 8GB of RAM and 256GB of storage: – 24″ M3 iMac/8-core GPU/8GB/256GB: $1149.99, $150... Read more
15-inch M3 MacBook Airs now on sale for $150...
Amazon is now offering a $150 discount on Apple’s new M3-powered 15″ MacBook Airs. Prices start at $1149 for models with 8GB of RAM and 256GB of storage: – 15″ M3 MacBook Air/8GB/256GB: $1149.99, $... Read more
The latest Apple Education discounts on MacBo...
If you’re a student, teacher, or staff member at any educational institution, you can use your .edu email address when ordering at Apple Education to take up to $300 off the purchase of a new MacBook... Read more

Jobs Board

Early Preschool Teacher - Glenda Drive/ *Appl...
Early Preschool Teacher - Glenda Drive/ Apple ValleyTeacher Share by Email Share on LinkedIn Share on Twitter Read more
Retail Assistant Manager- *Apple* Blossom Ma...
Retail Assistant Manager- APPLE BLOSSOM MALL Brand: Bath & Body Works Location: Winchester, VA, US Location Type: On-site Job ID: 04225 Job Area: Store: Management Read more
Housekeeper, *Apple* Valley Village - Cassi...
Apple Valley Village Health Care Center, a senior care campus, is hiring a Part-Time Housekeeper to join our team! We will train you for this position! In this role, Read more
Sonographer - *Apple* Hill Imaging Center -...
Sonographer - Apple Hill Imaging Center - Evenings Location: York Hospital, York, PA Schedule: Full Time Sign-On Bonus Eligible Remote/Hybrid Regular Apply Now See Read more
Senior Software Engineer - *Apple* Fundamen...
…center of Microsoft's efforts to empower our users to do more. The Apple Fundamentals team focused on defining and improving the end-to-end developer experience in Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.