Is a period a number

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
kpassaur
Automation Wizard
Posts: 696
Joined: Wed Jul 07, 2004 1:55 pm

Is a period a number

Post by kpassaur » Sun Mar 06, 2011 10:00 am

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

Jerry Thomas
Macro Veteran
Posts: 267
Joined: Mon Sep 27, 2010 8:57 pm
Location: Seattle, WA

Post by Jerry Thomas » Mon Mar 07, 2011 5:56 pm

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.

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
Suggestions?
Thanks,
Jerry

[email protected]

kpassaur
Automation Wizard
Posts: 696
Joined: Wed Jul 07, 2004 1:55 pm

for simplicity

Post by kpassaur » Mon Mar 07, 2011 6:09 pm

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.

Jerry Thomas
Macro Veteran
Posts: 267
Joined: Mon Sep 27, 2010 8:57 pm
Location: Seattle, WA

Post by Jerry Thomas » Mon Mar 07, 2011 6:09 pm

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
Thanks,
Jerry

[email protected]

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts