mje Posted May 11, 2011 Report Share Posted May 11, 2011 Is there a native way of determining what the localized decimal separator is? I have a combo box which I'm hacking up to be a pseudo-numeric control, insomuch as I want to be able to enter any positive real value, or allow the user to select from a set of pre-determined special values which are text. So I populate the Strings[] of the combo box with the relevant strings, and leave it to the user to enter any numeric values on their own. When the value changes, I parse the value for a numeric if it's not one of the matched strings, then re-write the parsed value back to the control to make sure whatever is being displayed matches with the value I'm tracking on my data wire. Works pretty well. The only problem is the user can of course still enter anything they want in there. If I have the strings "Fee" and "Fie" available, the user can enter "Foe" by typing it in. This doesn't cause a problem since I parse and write back to the control, but I'd like to be able to have it be more like a numeric control, where you can't enter invalid characters. Try to enter any non-numeric related character into a numeric control, you can't do it. I could easily implement this via the Key Down? event structure frame, but how do I distinguish what a valid decimal character is? In a North American locale I'd allow a "." character, but in France I wouldn't, for example. I'm aware of the %.; %,; and %; codes which help with scanning an entire string for a number, but in this case I'm trying to match only a single character and I don't think they are of much help. 1 Quote Link to comment
Mellroth Posted May 12, 2011 Report Share Posted May 12, 2011 I could easily implement this via the Key Down? event structure frame, but how do I distinguish what a valid decimal character is? In a North American locale I'd allow a "." character, but in France I wouldn't, for example. I'm aware of the %.; %,; and %; codes which help with scanning an entire string for a number, but in this case I'm trying to match only a single character and I don't think they are of much help. Why not check the local decimal point before the event handling, e.g. by converting a number to string and check for the decimal character in the string? Then use this information to determine if ',' or '.' should be allowed in the Key Down? event. /J Quote Link to comment
Ton Plomp Posted May 12, 2011 Report Share Posted May 12, 2011 I would use the following construct to determine the decimal sign of my PC: Ton Quote Link to comment
mje Posted May 12, 2011 Author Report Share Posted May 12, 2011 Excellent ideas. Thank you both. Quote Link to comment
Jimmy Chretien Posted March 11, 2015 Report Share Posted March 11, 2015 By the way, I created my own subVI but just found this native VI used by the formula parser, the idea is similar as Ton's. ..\vi.lib\gmath\parser.llb\Dot or Comma.vi Quote Link to comment
Francois Normandin Posted March 12, 2015 Report Share Posted March 12, 2015 Jimmy, that's a good find. However, it seems like it's not doing what it's supposed to... Quote Link to comment
eberaud Posted March 12, 2015 Report Share Posted March 12, 2015 Weird. There is a similar check inside ...\vi.lib\gmath\parser.llb\Number Split.VI but this one seems right (44:comma, 46:dot) Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.