Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Currency and decimal convertor
#9
Shows how to convert numbers, currency, time and date format from your locale to US locale and back.
Also can be useful as format converter.
Function dlg_locale
Code:
Copy      Help
\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages

str controls = "4 6 7"
str e4 e6 cb7
cb7="&Number[]Currency[]Time[]Date"
if(!ShowDialog("dlg_locale" &dlg_locale &controls)) ret

;BEGIN DIALOG
;0 "" 0x90C80A44 0x100 0 0 127 58 "Locale Converter"
;3 Static 0x54000000 0x0 2 22 48 12 "In your locale"
;4 Edit 0x54030080 0x200 56 20 68 14 ""
;5 Static 0x54000000 0x0 2 42 46 12 "In US locale"
;6 Edit 0x54030080 0x200 56 40 68 14 ""
;7 ComboBox 0x54230243 0x0 2 4 54 213 ""
;END DIALOG
;DIALOG EDITOR: "" 0x2030009 "*" "" ""

ret
;messages
sel message
,case WM_INITDIALOG
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
str s
int hr
BSTR b
double d
CURRENCY c
DATE da
sel wParam
,case CBN_SELENDOK<<16|7
,_s.setwintext(id(4 hDlg)); _s.setwintext(id(6 hDlg))
,
,case [EN_CHANGE<<16|4,EN_CHANGE<<16|6]
,if(GetFocus!lParam) ret
,int tous(wParam&0xffff=4) l1(iif(tous LOCALE_USER_DEFAULT 0x409)) l2(iif(tous 0x409 LOCALE_USER_DEFAULT))
,s.getwintext(lParam)
,if(s.len)
,,b=s
,,sel CB_SelectedItem(id(7 hDlg))
,,,case 0 hr=VarR8FromStr(b l1 0 &d); if(!hr) hr=VarBstrFromR8(d l2 0 &b)
,,,case 1 hr=VarCyFromStr(b l1 0 &c); if(!hr) hr=VarBstrFromCy(c l2 0 &b)
,,,case [2,3] hr=VarDateFromStr(b l1 0 &da); if(!hr) hr=VarBstrFromDate(da l2 0 &b)
,,if(hr) s.dllerror("" "" hr); else s=b
,s.setwintext(id(iif(tous 6 4) hDlg))
,
,case IDOK
,case IDCANCEL
ret 1


Messages In This Thread

Forum Jump:


Users browsing this thread: 2 Guest(s)