How do I create a big calculator using buttons?

BlitzPlus Forums/BlitzPlus Beginners Area/How do I create a big calculator using buttons?

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

About the background for keys: blitz buttons are simply the buttons of your OS .. there're no native imagebuttons.. (tho I've seen something once in some topic, but it was using external stuff iirc..)

window=CreateWindow("calc example - CS_TBL",0,0,384,384)

button0=CreateButton("0",20,264,24,24,window)
buttondot=CreateButton(".",44,264,24,24,window)
buttonis=CreateButton("=",68,264,48,24,window)
button1=CreateButton("1",20,240,24,24,window)
button2=CreateButton("2",44,240,24,24,window)
button3=CreateButton("3",68,240,24,24,window)
button4=CreateButton("4",20,216,24,24,window)
button5=CreateButton("5",44,216,24,24,window)
button6=CreateButton("6",68,216,24,24,window)
button7=CreateButton("7",20,192,24,24,window)
button8=CreateButton("8",44,192,24,24,window)
button9=CreateButton("9",68,192,24,24,window)

buttonmin=CreateButton("-",92,192,24,24,window)
buttonplus=CreateButton("+",92,216,24,48,window)
buttonmul=CreateButton("*",116,192,24,24,window)
buttondiv=CreateButton("/",116,216,24,24,window)
buttonmod=CreateButton("%",116,240,24,24,window)
buttonexp=CreateButton("^",116,264,24,24,window)
buttonbracketopen=CreateButton("(",140,192,24,24,window)
buttonbracketclose=CreateButton(")",140,216,24,24,window)
buttonback=CreateButton("<-",140,240,24,24,window)
buttonclear=CreateButton("C",140,264,24,24,window)

Global cmd$

Global display=CreateTextField(20,160,96,24,window)

Repeat
	WaitEvent()
	If EventID()=$803 quit=True
	
	If EventID()=$401
		If EventSource()=button0 addcmd "0"
		If EventSource()=button1 addcmd "1"
		If EventSource()=button2 addcmd "2"
		If EventSource()=button3 addcmd "3"
		If EventSource()=button4 addcmd "4"
		If EventSource()=button5 addcmd "5"
		If EventSource()=button6 addcmd "6"
		If EventSource()=button7 addcmd "7"
		If EventSource()=button8 addcmd "8"
		If EventSource()=button9 addcmd "9"
		If EventSource()=buttonmin addcmd "-"
		If EventSource()=buttonplus addcmd "+"
		If EventSource()=buttonmul addcmd "*"
		If EventSource()=buttondiv addcmd "/"
		If EventSource()=buttonexp addcmd "^"
		If EventSource()=buttonbracketopen addcmd "("
		If EventSource()=buttonbracketclose addcmd ")"
		If EventSource()=buttonclear addcmd "clear"
		If EventSource()=buttonback addcmd "bs"
		If EventSource()=buttonis
			; find the eval# function in the codearchives, and use it on cmd$
			; put the result in the display using: "updatedisplay result$"
		EndIf
	EndIf
Until quit
End

Function addcmd(s$)
	Select s$
		Case "clear"
			cmd$=""
		Case "bs'
			cmd$=Left$(cmd$,Len(cmd$)-1)
		Default
			cmd$=cmd$+s$
	End Select
	updatedisplay(cmd$)
End Function

Function updatedisplay(s$)
	SetGadgetText display,s$
End Function