Is a period a number
Moderators: JRL, Dorian (MJT support)
Is a period a number
I am creating a Dialog box where a user enters a percentage and when I enter the decimal point it generates an error as I have it limited to numbers only. So, it is really not numbers only, but whole numbers only. It would be nice a decimal point could be entered
-
- Macro Veteran
- Posts: 267
- Joined: Mon Sep 27, 2010 8:57 pm
- Location: Seattle, WA
I was just about to post the same issue. I am trying to catch the entry when the user leaves the text box and edit it for them. But this is what I am running into.
Suggestions?
Code: Select all
Let>X=.5
GoSub>FixDecimal
//X=0.5
Let>X=0.5
GoSub>FixDecimal
//X=00.5
Let>X=-0.5
GoSub>FixDecimal
//X=-00.5
SRT>FixDecimal
MidStr>X,1,1,X1stChar
If>X1stChar=.
Let>X=0%X%
Else
MidStr>X,1,2,X1st2ndChar
If>X1st2ndChar=-.
MidStr>X,2,100,RemainingX
Let>X=-0%RemainingX%
Endif
Endif
End>FixDecimal
for simplicity
This is not perfect as you could have something in it that is not a period or a number such as a #@$ etc.
Let>pattern=[letter]
RegEx>pattern,Gpercentage,1,matches,num,0
If>num>0
MDL>There is an error in the percentage specified it will be tested at 2.00 percent
Let>Gpercentage=2.0
Endif
You could make it better by adding all puncuation and then testing for one period.
Let>pattern=[letter]
RegEx>pattern,Gpercentage,1,matches,num,0
If>num>0
MDL>There is an error in the percentage specified it will be tested at 2.00 percent
Let>Gpercentage=2.0
Endif
You could make it better by adding all puncuation and then testing for one period.
-
- Macro Veteran
- Posts: 267
- Joined: Mon Sep 27, 2010 8:57 pm
- Location: Seattle, WA
This is embarassing but I just had a brain storm and came up with this, which works! So I solved my own problem and maybe kpassaur's?
Code: Select all
//X is the dialog control text value that I get with
//a AddDialogHandler 'OnExit'
Let>X=.5
GoSub>FixDecimal
//X=0.5
Let>X=0.5
GoSub>FixDecimal
//X=0.5
Let>X=-.5
GoSub>FixDecimal
//X=-0.5
SRT>FixDecimal
MidStr>X,1,1,X1stChar
Pos>.,X,0,DecimalPos
If>DecimalPos=1
Let>X=0%X%
Else
Pos>-,X,0,MinusPos
If>{(%DecimalPos%=2) and (%MinusPos%=1)}
MidStr>X,2,100,RemainingX
Let>X=-0%RemainingX%
Endif
Endif
End>FixDecimal