Page 1 of 1

NAT1125: Too many significant digits in numeric input value

PostPosted: Fri Aug 05, 2011 3:06 am
by D9988
I'm getting this error when entering a number that is too big for the field (for example, if I enter 999 for a N1.4 field).

I would like to catch this situation and display a more meaningful error message if possible. Is it possible to bypass the Natural system error and display my own error message?

I tried it using a few variations of ON-ERROR / IF *ERROR-NR = 1125, REINPUT " " , but it still is displaying the system error.

I'm thinking it's possible to work with the field as an alpha instead, but I would like to avoid having to do that if possible.

Re: NAT1125: Too many significant digits in numeric input va

PostPosted: Fri Aug 05, 2011 1:32 pm
by RGZbrog
Yes, we all fight this one. :D

Natural sends the message due to an error condition, and he does not relinquish control (back to your program) until the error is resolved. So the ON ERROR and IF *ERROR-NR statements won't execute until the user fixes the problem - too late.

Change the input field from numeric to alpha. Then decide if you want to make things easy for yourself or for your user. I recommend the latter.

If the user knows that the input must be entered in the format number-decimal-number-number-number-number, then you can use the MASK clause.
DEFINE DATA LOCAL
1 #A (A6)
  ...
  IF  NOT #A = MASK (N'.'NNNN)
    THEN
      REINPUT 'Enter a value of format N1.4'
  END-IF
But this doesn't allow flexibility for input values such as "1.1" or ".123", nor does it allow for negative values.

For flexibility, use the VAL function. But now you need to be concerned with too many decimal digits. That is, the user could enter ".12345" and VAL will truncate.
DEFINE DATA LOCAL
1 #A (A7)                         /* allow for negative
1 #T (N5.6)                       /* too many decimals
1 #N (N1.4)
END-DEFINE
REPEAT
  INPUT '  Input:' #A (AD=M)
     // 'Numeric:' #N (AD=O)
  IF  #A IS (N1.4)
    THEN
      IF  #A <> ' '
        THEN
          #N := VAL (#A)
          #T := VAL (#A) * 10000  /* too many decimals
          IF  FRAC (#T) <> 0      /* too many decimals
            THEN
              REINPUT FULL 'Too many decimal positions'
          END-IF
        ELSE
          RESET #N
      END-IF
    ELSE
      REINPUT 'Enter a value of format N1.4'
  END-IF
END-REPEAT
END
Note that the input value is tested for non-blank, as older versions of Natural will abend when VAL is presented with a blank.

Re: NAT1125: Too many significant digits in numeric input va

PostPosted: Sat Aug 06, 2011 12:49 am
by D9988
Thanks for the helpful info :D

I also learned something new about VAL and FRAC (which I never have seen used before), and the ability to use an expression like IF #A IS (N1.4)

Thanks again!

Re: NAT1125: Too many significant digits in numeric input va

PostPosted: Wed Dec 21, 2016 9:22 pm
by DanielInBIS
How do we easily identify the errant field if there are a lot of them on the stack?

Re: NAT1125: Too many significant digits in numeric input va

PostPosted: Wed Dec 21, 2016 11:10 pm
by Akatsukami
Not by reanimating a five-year-old thread.