홈 · 개발 참고자료

개발 참고자료

[파워빌더] Determine what is the decimal or hundred separator at runtime

작성자
관리자
작성일
2016-10-16
조회
10363
분류
파워빌더
When writing or reading data from or to a file, PB uses the current user settings to determine what are the separators used. You may want to take extra steps to ensure that the separator used is a known one (like a "." for decimal). Simply read the registry to get the current separator value and keep it. Modify the Registry for the desired separator. Then do your processing and after put back the original separator value.string ls_decimal, ls_thousand
string ls_regKey = "HKEY_CURRENT_USER/Control Panel/International"
RegistryGet(ls_regKey, "sDecimal", ls_decimal)
RegistryGet(ls_regKey, "sThousand", ls_thousand)

You may need to notify Windows applications that a change in the regional settings has been made. You broadcast the WM_SETTINGCHANGE message then Windows applications will react to that change.[local function declaration]
FUNCTION long SendMessageA &
( long hwnd, uint Msg, long wparam, string lparam) &
LIBRARY "USER32"

[powerscript]
long HWND_BROADCAST = 65535
uint WM_SETTINGCHANGE = 26

String ls_separator
String ls_regKey = "HKEY_CURRENT_USER\Control Panel\International"

RegistryGet(ls_regkey, "sDecimal", RegString!, ls_separator)

messagebox("current separator", ls_separator)
IF ls_separator <> "." THEN
// make sure it's a "."
RegistrySet(ls_regkey, "sDecimal", RegString!, ".")
SendMessageA( HWND_BROADCAST, WM_SETTINGCHANGE, 0, 'intl' )
END IF

// dbf format requires a "." as the separator
dw_1.saveas("data.dbf" , dbase3!, true)

// put back the original value
RegistrySet(ls_regkey, "sDecimal", RegString!, ls_separator)
SendMessageA( HWND_BROADCAST, WM_SETTINGCHANGE, 0, 'intl' )

NOTE: On Win9x, you need to modify the win.ini (not the registry) file using the ProfileString() function.A simple way to get the decimal separator without querying the Registry is :


IF pos(string(1/2), ".") > 0 THEN
messagebox("dot", ".")
ELSE
messagebox("comma", ",")
END IF

Thanks to C. Frenné for the tip!You may want to check this HowTo.