Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dialog edit text box math
#5
Function Simple_Calc
Code:
Copy      Help
\Dialog_Editor

str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 244 114 "Simple Calculator"
;3 Edit 0x54030080 0x200 40 16 52 16 ""
;4 Edit 0x54030080 0x200 100 16 56 16 ""
;5 Edit 0x54030080 0x200 164 16 76 16 ""
;10 Static 0x54000000 0x0 41 4 48 12 "Number 1"
;11 Static 0x54000000 0x0 101 4 48 12 "Number 2"
;12 Static 0x54000000 0x0 166 4 48 12 "Result"
;6 Edit 0x54030080 0x200 40 36 52 14 ""
;7 Edit 0x54030080 0x200 100 36 56 14 ""
;8 Edit 0x54030080 0x200 164 36 76 14 ""
;9 Edit 0x54030080 0x200 40 56 50 14 ""
;13 Edit 0x54030080 0x200 100 56 56 14 ""
;14 Edit 0x54030080 0x200 164 56 76 14 ""
;15 Edit 0x54030080 0x200 40 76 52 14 ""
;16 Edit 0x54030080 0x200 100 76 56 14 ""
;17 Edit 0x54030080 0x200 164 76 76 14 ""
;18 Static 0x54000000 0x0 4 20 34 12 "Add"
;19 Static 0x54000000 0x0 4 40 34 12 "Subtract"
;20 Static 0x54000000 0x0 4 60 34 12 "Multiply"
;21 Static 0x54000000 0x0 4 80 34 12 "Divide"
;2 Button 0x54030000 0x4 128 96 48 14 "Cancel"
;1 Button 0x54030001 0x4 184 96 48 14 "OK"
;END DIALOG
;DIALOG EDITOR: "" 0x2040202 "*" "" "" ""

str controls = "3 4 5 6 7 8 9 13 14 15 16 17"
str e3 e4 e5 e6 e7 e8 e9 e13 e14 e15 e16 e17
if(!ShowDialog(dd &sub.DlgProc &controls)) ret

#sub DlgProc
function# hDlg message wParam lParam

str s; double A B R; int divideByZero = 0

sel message
,case WM_INITDIALOG
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
,case [EN_CHANGE<<16|3, EN_CHANGE<<16|4] goto gAdd
,case [EN_CHANGE<<16|6, EN_CHANGE<<16|7] goto gSubtract
,case [EN_CHANGE<<16|9, EN_CHANGE<<16|13] goto gMultiply
,case [EN_CHANGE<<16|15, EN_CHANGE<<16|16] goto gDivide
,
ret 1

;gAdd
s.getwintext(id(3 hDlg)); A=val(s 2)
s.getwintext(id(4 hDlg)); B=val(s 2)
R=A+B ;; Add
s=R; s.setwintext(id(5 hDlg))
ret

;gSubtract
s.getwintext(id(6 hDlg)); A=val(s 2)
s.getwintext(id(7 hDlg)); B=val(s 2)
R=A-B ;; Subtract
s=R; s.setwintext(id(8 hDlg))
ret

;gMultiply
s.getwintext(id(9 hDlg)); A=val(s 2)
s.getwintext(id(13 hDlg)); B=val(s 2)
R=A*B ;; Multiply
s=R; s.setwintext(id(14 hDlg))
ret

;gDivide
s.getwintext(id(15 hDlg)); A=val(s 2)
s.getwintext(id(16 hDlg)); if(s.len) B=val(s 2); else B=1
if(B=0) mes "Could not divide by zero!"; divideByZero=1
else R=A/B
if(!divideByZero) s=R; s.setwintext(id(17 hDlg))
ret


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)