Page 2 of 2

Re: Comma and decimal point as a decimal separator

Posted: Sat Nov 05, 2011 10:56 am
by raumi75
Watching my users occasionally struggle with the rather strict NUMERIC textboxes in hmg, I noticed several difficulties:

It is not only the comma / point confusion. With the cursor on the very right, users want to delete all characters by pressing backspace, but can't get past the decimal point because it is protected. Iif the cursor is on the left and you use the delete key only one character gets deleted and neither the following numbers, nor the caret moves. So if you press a second time, nothing happens.

This behavior is different from console-mode, where you can delete all numbers by pressing del or backspace several times. Neither is it consistent with other windows-programs like excel.

To give my users a bit of freedom, I declared textboxes as CHARACTER and bound them to database-fields by means of onChange and onLostfocus events. My users are happy, but my code does not look nice.

Because I was unhappy with my ugly hack, I altered hmg-sourcecode h_windows and removed the line 1467

Code: Select all

ProcessCharmask ( i , .t. )
Now the InputMask is ignored during typing, but only used to format the input to a valid number when the control loses focus. Hmg does a pretty good job transforming it to a valid number. Only one alternation is necessary if you use FORMAT "E" (decimal-comma). If a user does not type "," or ".", the INPUTMASK is ignored. That is because in line 1511ff there, an otherwise-clause is missing.

So I replaced

Code: Select all

Do Case
   Case At ( '.' , Ts ) >  At ( ',' , Ts ) 
      SetWindowText ( _HMG_SYSDATA [3] [i] , Transform ( GetNumFromText ( GetWindowText ( _HMG_SYSDATA [3][i] )  , i )  , _HMG_SYSDATA [  7 ][i] ) )
   Case At ( ',' , Ts ) > At ( '.' , Ts )
      SetWindowText ( _HMG_SYSDATA [3] [i] , Transform ( GetNumFromTextSp ( GetWindowText ( _HMG_SYSDATA [3][i] )  , i )  , _HMG_SYSDATA [  7 ][i] ) )
EndCase
with this

Code: Select all

IF At ( ',' , Ts ) > At ( '.' , Ts )
   SetWindowText ( _HMG_SYSDATA [3] [i] , Transform ( GetNumFromTextSp ( GetWindowText ( _HMG_SYSDATA [3][i] )  , i )  , _HMG_SYSDATA [  7 ][i] ) )
else
   SetWindowText ( _HMG_SYSDATA [3] [i] , Transform ( GetNumFromText ( GetWindowText ( _HMG_SYSDATA [3][i] )  , i )  , _HMG_SYSDATA [  7 ][i] ) )
endif
I suggest a new option to enable this behavior. Maybe FORMATMASK as opposed to INPUTMASK. So programers can decide if the mask should be checked during or after input.

What do you think?

Re: Comma and decimal point as a decimal separator

Posted: Sat Nov 05, 2011 11:09 am
by Rathinagiri
Nice idea Raumi. Here, the users are allowed to enter other characters too?

Re: Comma and decimal point as a decimal separator

Posted: Sat Nov 05, 2011 11:28 am
by raumi75
Yes, users could type any character. But the program handles it very gracefully. If you type "aasdf28.asdf50" and leave the textbox, it will turn into "28.50". If you use Format "E" as is common in many european countries, "asdf15,30" will be turned into the numeric value 15.30 and displayed as 15,30. If you accidentally type more than one decimal point (or comma), all but the last one are ignored.