Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to input into dialog edit box in currency format
#1
hello,

I have created a macro which when called up presents a dialog box and allows the user to select from combo boxes, details for construction jobs.
when everything is selected the macro then paste's a text block of all details into the application which the macro was called from.

My question is how do I set up the dialog to have one of the edit box's (e7Pri) accept only numbers in double format i.e 0000.00. then when this is output
convert it to currency format i.e £0000.00

I am just starting to learn Quickmacros, and this particular problem has me beat.





Function Dialog7
Code:
Copy      Help
;\Dialog_Editor


;BEGIN DIALOG
;0 "" 0x90C81AC8 0x0 0 0 201 173 "Installation Detail"
;3 ComboBox 0x54230242 0x0 70 12 100 213 "Site"
;4 ComboBox 0x54230242 0x0 70 30 100 213 "HouseType"
;5 Edit 0x54030080 0x200 70 48 100 14 "PlotNo"
;6 Edit 0x54032080 0x200 70 66 100 14 "CPR"
;7 Edit 0x54030040 0x200 70 84 50 14 "Price" "Enter the installation price in here"
;8 Static 0x54000200 0x0 16 12 48 13 "Site:"
;9 Static 0x54000200 0x0 16 30 48 12 "Housetype:"
;10 Static 0x54000200 0x0 16 48 48 13 "Plot No:"
;11 Static 0x54000200 0x0 16 66 48 12 "CPR No:"
;12 Static 0x54000200 0x0 16 84 48 13 "Price:"
;13 Button 0x54012003 0x0 70 104 48 12 "Complete:"
;2 Button 0x54030000 0x4 120 124 48 14 "Cancel"
;1 Button 0x54030001 0x0 70 124 48 14 "OK"
;END DIALOG
;DIALOG EDITOR: "" 0x2030502 "" "" "" ""


Macro Macro29
Trigger CS(223)     Help - how to add the trigger to the macro
Code:
Copy      Help
out
str controls = "3 4 5 6 7 13"
str cb3Sit cb4Hou e5Plo e6CPR e7Pri c13Com status
if(dir("D:\Automation\Quick Macros 2\Macro Text Files\sites.txt"))
,cb3Sit.getfile("D:\Automation\Quick Macros 2\Macro Text Files\sites.txt")
else mes "The Sites.txt file does not exist, please create it first ";ret
ARRAY(str) a1=cb3Sit
a1.sort(2)
cb3Sit=a1
if(dir("D:\Automation\Quick Macros 2\Macro Text Files\Housetype.txt"))
,cb4Hou.getfile("D:\Automation\Quick Macros 2\Macro Text Files\Housetype.txt")
else mes "The Housetype.txt file does not exist, please create it first ";ret
ARRAY(str) a2=cb4Hou
a2.sort(2)
cb4Hou=a2
if(!ShowDialog("Dialog7" 0 &controls)) ret
if c13Com=1
,status = "complete installation";    
else status =
F
;incomplete installation
;Items requiring attention.....
TO_CBGetItem(cb3Sit);TO_CBGetItem(cb4Hou)
str output=
F
;------------------------------
;Site :     {cb3Sit}
;Housetype: {cb4Hou}
;Plot No:   {e5Plo}
;CPR No:    {e6CPR}
;Price:     £{e7Pri}
;------------------------------
;{status}
paste output
#2
To validate dialog controls without closing the dialog, it must be 'smart' dialog, ie with dialog procedure. Example:
Function dialog_edit_currency
Code:
Copy      Help
\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages

;note: this code (4 lines) can be in other macro
str controls = "7"
str e7Pri
if(!ShowDialog("dialog_edit_currency" &dialog_edit_currency &controls)) ret
out e7Pri

;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 223 135 "Dialog"
;7 Edit 0x54030080 0x200 8 10 96 14 "Price"
;1 Button 0x54030001 0x4 120 116 48 14 "OK"
;2 Button 0x54030000 0x4 170 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2030503 "" "" "" ""

ret
;messages
sel message
,case WM_INITDIALOG
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,str s.getwintext(id(7 hDlg))
,CURRENCY cy=s; err
,if cy<=0
,,mes "incorret currency format"
,,ret ;;don't close dialog
,case IDCANCEL
ret 1
#3
I am very grateful for your help Gintaras. I am just starting out with QM and have a lot to learn. I intend to study your solution and rework the macro with a smart dialog.

Another question. Is it possible, using my original macro, to convert the str variable e7Pri to a numeric double format. No validation needed i.e the user must enter the string in the format 0000.00 or even 0000 and QM would append .00 as it converts the string to a double. I hope i have explained this correctly. I am asking this purely to learn more about the workings of QM.
#4
Macro Macro2027
Code:
Copy      Help
str e7Pri="234.5"
;str e7Pri="20"
;str e7Pri="88234.599"
;str e7Pri=""

double d=val(e7Pri 2) ;;convert string to number format
e7Pri.format("%07.2f" d) ;;format string from double, like with C/C++ printf function
out e7Pri

;f - format as double, without E.
;.2 - always 2 digits after ..
;7 - minimum 7 characters length.
;0 - prepend 0 if need, instead of spaces.
#5
Thank you again Gintaras, I have learned a lot from your replies.


Forum Jump:


Users browsing this thread: 1 Guest(s)