[code=basic]
Enumeration
#Window_0
EndEnumeration
Enumeration
#String
#Backs
#CE
#C
#But_7
#But_8
#But_9
#But_4
#But_5
#But_6
#But_1
#But_2
#But_3
#But_0
#znak
#drob
#delen
#umnoj
#minus
#plus
#sqrt
#pros
#fff
#rezul
#MC
#MR
#MS
#M_plus
EndEnumeration
Global rez3.d
Procedure.s DelNull(String.s) ;delete zero
Protected Result.s
Result=String
Pos=FindString(String, ".", 1)
If Pos>0
Len=Len(String)
For i=Len To Pos Step -1
Char.s=Mid(String, i, 1)
If Char="."
i-1
Break
ElseIf Char<>"0"
Break
EndIf
Next i
If i<Len
Result=Left(String, i)
EndIf
EndIf
ProcedureReturn Result
EndProcedure
;{------------------window--------------------------------
OpenWindow (#Window_0, 0, 0, 265, 240, "CalcX", #PB_Window_MinimizeGadget |#PB_Window_MaximizeGadget|#PB_Window_ScreenCentered|#PB_Window_SizeGadget)
SetWindowColor(#Window_0,RGB(255, 255, 255))
StringGadget(#String, 10, 15, 245, 25, "")
ButtonGadget(#Backs, 55, 50, 70, 30, "Backspace")
ButtonGadget(#CE, 130, 50, 60, 30, "CE")
ButtonGadget(#C, 195, 50, 60, 30, "C")
ButtonGadget(#But_7, 55, 90, 35, 30, "7")
ButtonGadget(#But_8, 95, 90, 35, 30, "8")
ButtonGadget(#But_9, 135, 90, 35, 30, "9")
ButtonGadget(#But_4, 55, 125, 35, 30, "4")
ButtonGadget(#But_5, 95, 125, 35, 30, "5")
ButtonGadget(#But_6, 135, 125, 35, 30, "6")
ButtonGadget(#But_1, 55, 160, 35, 30, "1")
ButtonGadget(#But_2, 95, 160, 35, 30, "2")
ButtonGadget(#But_3, 135, 160, 35, 30, "3")
ButtonGadget(#But_0, 55, 195, 35, 30, "0")
ButtonGadget(#znak, 95, 195, 35, 30, "+/-")
ButtonGadget(#drob, 135, 195, 35, 30, ".")
ButtonGadget(#delen, 180, 90, 35, 30, "/")
ButtonGadget(#umnoj, 180, 125, 35, 30, "*")
ButtonGadget(#minus, 180, 160, 35, 30, "-")
ButtonGadget(#plus, 180, 195, 35, 30, "+")
ButtonGadget(#sqrt, 220, 90, 35, 30, "sqrt")
ButtonGadget(#pros, 220, 125, 35, 30, "%")
ButtonGadget(#fff, 220, 160, 35, 30, "1/x")
ButtonGadget(#rezul,220, 195, 35, 30, "=")
ButtonGadget(#MC, 10, 90, 35, 30, "MC")
ButtonGadget(#MR, 10, 125, 35, 30, "MR")
ButtonGadget(#MS, 10, 160, 35, 30, "MS")
ButtonGadget(#M_plus,10, 195, 35, 30, "M+")
DisableGadget(#Backs, 1): DisableGadget(#sqrt, 1): DisableGadget(#pros, 1): DisableGadget(#fff, 1)
DisableGadget(#MC, 1): DisableGadget(#MR, 1): DisableGadget(#MS, 1): DisableGadget(#M_plus, 1)
;}------------------------------------------------------
rez1.d = 0
znak.s = "0"
umn1.d = 1
um.d = 1
oper.s ="0"
fff.s = "0"
;{----------------- main loop -------------------------
Repeat
Event = WaitWindowEvent()
Window = EventWindow()
Gadget = EventGadget()
Select Event
Case #PB_Event_Gadget
Select EventGadget()
Case #But_0,#But_1,#But_2,#But_3,#But_4,#But_5,#But_6,#But_7,#But_8,#But_9,#drob
If znak = "0"
rez0.s = GetGadgetText(#String)
SetGadgetText(#String, rez0+GetGadgetText(Gadget))
ElseIf znak = "+"
SetGadgetText(#String, "")
rez0.s = GetGadgetText(#String)
SetGadgetText(#String, rez0+GetGadgetText(Gadget))
znak = "0"
ElseIf znak = "-"
SetGadgetText(#String, "")
rez0.s = GetGadgetText(#String)
SetGadgetText(#String, "-"+rez0+GetGadgetText(Gadget))
znak = "0"
ElseIf znak = "*" And oper = "0"
SetGadgetText(#String, "")
rez0.s = GetGadgetText(#String)
SetGadgetText(#String, rez0+GetGadgetText(Gadget))
znak = "0"
oper = "*"
ElseIf znak = "/" And oper = "0"
SetGadgetText(#String, "")
rez0.s = GetGadgetText(#String)
SetGadgetText(#String, rez0+GetGadgetText(Gadget))
znak = "0"
oper = "/"
EndIf
Case #C , #CE
SetGadgetText(#String, "")
rez1 = 0
znak ="0"
POSL = 0
rez3 = 0
rav_r = 0
umn1 = 1
um.d = 1
oper ="0"
fff = "0"
Case #plus, #minus
If znak = "0" And oper = "0"
SetGadgetText(#String, DelNull(StrD(rez1 + ValD(GetGadgetText(#String)))))
rez1 = ValD(GetGadgetText(#String))
znak = GetGadgetText(Gadget)
oper = "0"
um =4
fff = "1"
ElseIf znak = "="
SetGadgetText(#String, "")
SetGadgetText(#String, DelNull(StrD(rez3)))
rez1 = ValD(GetGadgetText(#String))
znak = GetGadgetText(Gadget)
oper = "0"
rav_r=0
fff = "1"
ElseIf znak = "0" And oper = "*"
SetGadgetText(#String, DelNull(StrD(rez1 * ValD(GetGadgetText(#String)))))
rez1 = ValD(GetGadgetText(#String))
znak = GetGadgetText(Gadget)
oper = "0"
fff = "1"
ElseIf znak = "0" And oper = "/"
SetGadgetText(#String, DelNull(StrD(rez1 / ValD(GetGadgetText(#String)))))
rez1 = ValD(GetGadgetText(#String))
znak = GetGadgetText(Gadget)
oper = "0"
fff = "1"
EndIf
Case #umnoj
If um =1
SetGadgetText(#String, DelNull(StrD(1 * ValD(GetGadgetText(#String)))))
rez1 = ValD(GetGadgetText(#String))
znak = "*"
oper = "0"
um = 0
ElseIf um = 0 Or znak = "*"
SetGadgetText(#String, DelNull(StrD(rez1 * ValD(GetGadgetText(#String)))))
rez1 = ValD(GetGadgetText(#String))
znak = "*"
oper = "0"
ElseIf znak = "0" And oper = "0"
SetGadgetText(#String, DelNull(StrD(rez1 + ValD(GetGadgetText(#String)))))
rez1 = ValD(GetGadgetText(#String))
znak = "*"
oper = "0"
um = 0
ElseIf znak = "0" And oper = "/"
SetGadgetText(#String, DelNull(StrD(rez1 / ValD(GetGadgetText(#String)))))
rez1 = ValD(GetGadgetText(#String))
znak = "*"
oper = "0"
um = 0
ElseIf znak = "="
SetGadgetText(#String, "")
SetGadgetText(#String, DelNull(StrD(rez3)))
rez1 = ValD(GetGadgetText(#String))
znak = "*"
oper = "0"
um = 0
EndIf
Case #delen
If znak = "0" And oper = "0" And fff = "0"
rez1 = ValD(GetGadgetText(#String))
SetGadgetText(#String, DelNull(StrD(rez1 )))
znak = "/"
oper = "0"
um = 4
ElseIf znak = "0" And oper = "/"
SetGadgetText(#String, DelNull(StrD(rez1 / ValD(GetGadgetText(#String)))))
rez1 = ValD(GetGadgetText(#String))
znak = "/"
oper = "0"
um = 4
ElseIf znak = "="
SetGadgetText(#String, "")
SetGadgetText(#String, DelNull(StrD(rez3)))
rez1 = ValD(GetGadgetText(#String))
znak = "/"
oper = "0"
ElseIf znak = "0" And oper = "0" And fff = "1"
SetGadgetText(#String, DelNull(StrD(rez1 + ValD(GetGadgetText(#String)))))
rez1 = ValD(GetGadgetText(#String))
znak = "/"
oper = "0"
ElseIf znak = "0" And oper = "*"
SetGadgetText(#String, DelNull(StrD(rez1 * ValD(GetGadgetText(#String)))))
rez1 = ValD(GetGadgetText(#String))
znak = "/"
oper = "0"
EndIf
Case #rezul
If znak = "0" And oper = "0"
rez3 = rez1+ValD(GetGadgetText(#String))
POSL=ValD(GetGadgetText(#String))
rav_r=1
SetGadgetText(#String, DelNull(StrD(rez3)))
znak = "="
oper = "0"
um = 4
ElseIf rav_r=1 And oper = "0"
rez3=rez3+POSL
SetGadgetText(#String, DelNull(StrD(rez3)))
um = 4
ElseIf znak = "0" And oper = "*"
rez3 = rez1*ValD(GetGadgetText(#String))
POSL=ValD(GetGadgetText(#String))
SetGadgetText(#String, DelNull(StrD(rez3)))
znak = "="
um = 4
rav_r=2
ElseIf rav_r=2 And oper = "*"
rez3=rez3*POSL
SetGadgetText(#String, DelNull(StrD(rez3)))
um = 4
ElseIf znak = "0" And oper = "/"
rez3 = rez1/ValD(GetGadgetText(#String))
POSL=ValD(GetGadgetText(#String))
SetGadgetText(#String, DelNull(StrD(rez3)))
znak = "="
oper = "/"
rav_r=3
ElseIf rav_r=3 And oper = "/"
rez3=rez3/POSL
SetGadgetText(#String, DelNull(StrD(rez3)))
um = 4
EndIf
EndSelect
EndSelect
If Event = #PB_Event_CloseWindow
Break
EndIf
ForEver
[/code]