NAT1125: Too many significant digits in numeric input value



Software AG's platform-independent programming language with full support for open-source and Internet applications

NAT1125: Too many significant digits in numeric input value

Postby D9988 » Fri Aug 05, 2011 3:06 am

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.
David
D9988
 
Posts: 34
Joined: Fri Nov 09, 2007 10:55 pm
Has thanked: 0 time
Been thanked: 0 time

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

Postby RGZbrog » Fri Aug 05, 2011 1:32 pm

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.
User avatar
RGZbrog
 
Posts: 101
Joined: Mon Nov 23, 2009 1:34 pm
Location: California, USA
Has thanked: 0 time
Been thanked: 0 time

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

Postby D9988 » Sat Aug 06, 2011 12:49 am

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!
David
D9988
 
Posts: 34
Joined: Fri Nov 09, 2007 10:55 pm
Has thanked: 0 time
Been thanked: 0 time

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

Postby DanielInBIS » Wed Dec 21, 2016 9:22 pm

How do we easily identify the errant field if there are a lot of them on the stack?
DanielInBIS
 
Posts: 1
Joined: Wed Dec 21, 2016 9:15 pm
Has thanked: 0 time
Been thanked: 0 time

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

Postby Akatsukami » Wed Dec 21, 2016 11:10 pm

Not by reanimating a five-year-old thread.
"You have sat too long for any good you have been doing lately ... Depart, I say; and let us have done with you. In the name of God, go!" -- what I say to a junior programmer at least once a day
User avatar
Akatsukami
Global moderator
 
Posts: 1058
Joined: Sat Oct 16, 2010 2:31 am
Location: Bloomington, IL
Has thanked: 6 times
Been thanked: 51 times


Return to Natural

 


  • Related topics
    Replies
    Views
    Last post