Fixed/souped-up the whole shebang:
A few notes:
- note how I added whitelines, stick to that habit!
- get rid of the idea that you must put your waitevent into some function this is only relevant when doing popup-things that create, function and clear themself on their own. For instance, a popup bankmonitor, a popup color-selector, etc. you're still far from there, so don't bother yet.
I strongly advice you to keep my standard mainloop model! Which means you'll have a small mainloop with the Waitevent() (you don't need any bla=WaitEvent()), a simple check on window-close, and then only function calls to the actual functionality.
- You can debuglog a gadget, it'll show some very huge number, a sign it's created correctly. If you debuglog a gadget, and there's not any big number showing up then this gadget is not created correctly. Since this large number is equal to 'true' (which is any number except 0) you can check on the gadget's precent using
If MyGadget
; do your stuff here
Endif
- Make DAMN well sure that you *never* divide by zero. I dunno what OS you're running, but doing a /0 using B+ in 98se means that you may reboot. Not because your system freezes, but because nothing ever compiled with Blitz will run nor compile.
This check is quite simple:
If Value
Debuglog 1/Value
EndIf
This code is always correct as the IF checks whether it's 0 or not 0. When the condition is true it means that Value is not 0 and you can use it as divider.
bank=SetUp(window) ; Repeat WaitEvent() If EventID()=$803 quit=1 Math bank Until quit Notify("Bye bye, 'till next time") End ;Functions ;This function has a window parameter because of the bank Function SetUp(window) bank=CreateBank(35) PokeInt bank,5,CreateButton("+",100,200,75,75,window) PokeInt bank,10,CreateButton("-",200,200,75,75,window) PokeInt bank,15,CreateButton("*",300,200,75,75,window) PokeInt bank,20,CreateButton("/",400,200,75,75,window) PokeInt bank,25,CreateTextArea(100,100,50,50,window) PokeInt bank,30,CreateTextArea(400,100,50,50,window) ;So we can use this bank everywhere else Return bank End Function ;This function will allow us to add,subtract,multiply and divide. Function Math(bank) plus=PeekInt(bank,5) subtract=PeekInt(bank,10) multiply=PeekInt(bank,15) divide=PeekInt(bank,20) value1=PeekInt(bank,25) value2=PeekInt(bank,30) iValue1=Float(TextAreaText(value1)) iValue2=Float(TextAreaText(value2)) If EventID()=$401 Select EventSource() Case plus Notify("Answer: "+(iValue1+iValue2)) Case subtract Notify("Answer: "+(iValue1-iValue2)) Case multiply Notify("Answer: "+(iValue1*iValue2)) Case divide If iValue2=0 Notify "Error: divisione by zero" Else Notify "Answer: "+(iValue1/Float(iValue2)) EndIf End Select EndIf End Function
A few notes:
- note how I added whitelines, stick to that habit!
- get rid of the idea that you must put your waitevent into some function this is only relevant when doing popup-things that create, function and clear themself on their own. For instance, a popup bankmonitor, a popup color-selector, etc. you're still far from there, so don't bother yet.
I strongly advice you to keep my standard mainloop model! Which means you'll have a small mainloop with the Waitevent() (you don't need any bla=WaitEvent()), a simple check on window-close, and then only function calls to the actual functionality.
- You can debuglog a gadget, it'll show some very huge number, a sign it's created correctly. If you debuglog a gadget, and there's not any big number showing up then this gadget is not created correctly. Since this large number is equal to 'true' (which is any number except 0) you can check on the gadget's precent using
If MyGadget
; do your stuff here
Endif
- Make DAMN well sure that you *never* divide by zero. I dunno what OS you're running, but doing a /0 using B+ in 98se means that you may reboot. Not because your system freezes, but because nothing ever compiled with Blitz will run nor compile.
This check is quite simple:
If Value
Debuglog 1/Value
EndIf
This code is always correct as the IF checks whether it's 0 or not 0. When the condition is true it means that Value is not 0 and you can use it as divider.