Gui crash

BlitzPlus Forums/BlitzPlus Programming/Gui crash

schilcote(Posted 2008) [#1]
I'm not new to blitz, I've been using B2D since I was four, but B+ is pretty new to me with it's GUI functions. I wrote some code to test it out, but it crashes. What's wrong?

BUTTON_PRESS=$401

AppTitle "GUI Test"

Window=CreateWindow( "GUI Test",600,800,600,800 )
button1=CreateButton( "Button 1",0,0,100,100,Window )
button2=CreateButton( "Button 2",0,300,100,100,Window )
Repeat
Select WaitEvent 

Case BUTTON_PRESS
Exit
End Select

Forever

If EventSource=button1 Then
Print "You pressed button 1!"
Else
Print "You pressed button 2!"
EndIf
Delay 10000
End



TAS(Posted 2008) [#2]
Below is fixed code, there were several problems

1) AppTitle effects the built in notify, confirm and proceed windows and is not needed for windows created by you. <minor>

2) Your window is off screen <minor-major>

3) Written as EventSource instead of EventSource() it's treated as variable rather than a command even though its formatted by the IDE as a command. It should have been flagged by the IDE. This is an IDE bug

4) As good practive always use Waitevent(100) rather than Waitevent () as it might save you from an endless wait someday. Also using Waitevent() as a Select variable is probably bad practice.

Keep experimenting, you learn more from your mistakes than your success. Programming is best learned by trying create something you want to use yourself!




BUTTON_PRESS=$401

Window=CreateWindow( "GUI Test",100,100,200,200 )
button1=CreateButton( "Button 1",10,20,100,20,Window )
button2=CreateButton( "Button 2",10,60,100,20,Window )

Repeat
WaitEvent(100)
Select EventID()
Case BUTTON_PRESS
If EventSource()=button1 Then
S$="you pressed button 1!"
Else
S$="You pressed button 2!"
End If
Notify S$
Case $803
Exit
End Select
Forever

FreeGadget WINDOW
End


blackgecko(Posted 2008) [#3]
I just added the missing brackets after WaitEvent and EventSource and it works now.
I don't think it's necessary to add a parameter to WaitEvent().