Posts: 6
Threads: 2
Joined: Jul 2014
Hi
Could someone tell me how to get values from user imputed digits in text box and then perform arithmetic operation on those values so the calculation result is presented in other text box after pressing a button?
I tried some dialogs examples and forum posts but still cant make it happen.
Thanks,
Posts: 12,074
Threads: 141
Joined: Dec 2002
Function
dialog_calculator
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog"
;3 Edit 0x54030080 0x200 8 4 96 13 ""
;4 Edit 0x54030080 0x200 8 20 96 13 ""
;5 Edit 0x54030080 0x200 8 48 96 12 ""
;6 Static 0x54000000 0x0 8 36 48 13 "="
;7 Button 0x54032000 0x0 8 64 48 14 "+"
;8 Button 0x54032000 0x0 60 64 48 14 "-"
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040304 "*" "" "" ""
str controls = "3 4 5"
str e3 e4 e5
if(!ShowDialog(dd &sub.DlgProc &controls)) ret
#sub DlgProc
function# hDlg message wParam lParam
sel message
,case WM_INITDIALOG
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
,case [7,8] goto gCalc ;;+ -
ret 1
;gCalc
double A B R
str s
s.getwintext(id(3 hDlg)); A=val(s 2)
s.getwintext(id(4 hDlg)); B=val(s 2)
sel wParam
,case 7 R=A+B ;;+
,case 8 R=A-B ;;-
s=R; s.setwintext(id(5 hDlg))
Posts: 6
Threads: 2
Joined: Jul 2014
Thank you,
still got a question , when i try to remove the +- buttons option and let the result change in the real time (just after entering/changing the numerals) the macro runs very slow, kind of get stuck for a second when moving from one textbox to another, why is that?
Posts: 12,074
Threads: 141
Joined: Dec 2002
Function
dialog_calculator2
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog"
;3 Edit 0x54030080 0x200 8 4 96 13 ""
;4 Edit 0x54030080 0x200 8 20 96 13 ""
;5 Edit 0x54030080 0x200 8 48 96 12 ""
;6 Static 0x54000000 0x0 8 36 48 13 "="
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040304 "*" "" "" ""
str controls = "3 4 5"
str e3 e4 e5
if(!ShowDialog(dd &sub.DlgProc &controls)) ret
#sub DlgProc
function# hDlg message wParam lParam
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 gCalc
ret 1
;gCalc
double A B R
str s
s.getwintext(id(3 hDlg)); A=val(s 2)
s.getwintext(id(4 hDlg)); B=val(s 2)
R=A+B
s=R; s.setwintext(id(5 hDlg))
Posts: 133
Threads: 15
Joined: Jun 2014
Function
Simple_Calc
\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
Posts: 6
Threads: 2
Joined: Jul 2014
Thanks, thats whant i needed