Determine what is the decimal or hundred separator at runtimeTag(s): WinAPI/Registry
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)
[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' )
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
You may want to check this HowTo.
mail_outline
Send comment, question or suggestion to howto@rgagnon.com
Send comment, question or suggestion to howto@rgagnon.com