Using the IN operator - problem with decimal values

janmibjanmib Member Posts: 8
I have a code block like this:
IF Customer.verdi<>0 THEN BEGIN
IF verdi IN [0,1..3,0] THEN range:=1 ELSE
IF verdi IN [3,1..4,0] THEN range:=2 ELSE
IF verdi IN [4,1..5,0] THEN range:=3 ELSE
IF verdi IN [5,1..20,9] THEN range:=4 ELSE
range:=5;

I compiles but does not work as planned. The field verdi is a decimal field.
We use comma as a decimal separator. Range is not set according to the
value of customer verdi.

Any tips - maybe a better way ?

Comments

  • matttraxmatttrax Member Posts: 2,309
    IF Customer.verdi<>0 THEN BEGIN
      IF verdi > 0,1 AND verdi <= 3,0 THEN range:=1 ELSE
      IF verdi > 3,1 AND verdi <= 4,0 THEN range:=2 ELSE
      IF verdi > 4,1 AND verdi <= 5,0 THEN range:=3 ELSE
      IF verdi > 5,1 ABD verdi <= 20,9 THEN range:=4 ELSE
        range:=5;
    
  • MBergerMBerger Member Posts: 413
    or...
    if customer.verdi <> 0 then
      case true of
        customer.verdi <= 3 :
          Range := 1 ;
        customer.verdi <= 4 :
          Range := 2 ;
        customer.verdi <= 5 :
          Range := 3 ;
        customer.verdi <= 20.9 :
          Range := 4 ;
        else
          Range := 5 ;
      end ;
    
  • DenSterDenSter Member Posts: 8,307
    My vote goes to a CASE statement :mrgreen:
  • kinekine Member Posts: 12,562
    Try
    IF Customer.verdi<>0 THEN BEGIN
    IF verdi IN [0.1..3.0] THEN range:=1 ELSE
    IF verdi IN [3.1..4.0] THEN range:=2 ELSE
    IF verdi IN [4.1..5.0] THEN range:=3 ELSE
    IF verdi IN [5.1..20.9] THEN range:=4 ELSE
    range:=5;
    

    The decimal separator is . not , - , is value separator. It means your code have meaning
    if verdi is [0 or (1..3) or 0] ...
    
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
Sign In or Register to comment.