ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Find Lowest value

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Find Lowest value

    I have 5 numeric fields on a screen that I am displaying. They would like the 6th field to display the lowest number of the 5. This is an old program. I was wondering if there is a BIF or an easy way to calculate the lowest value?

    Example
    Lowest
    550 620 557 601 801 550


    Thanks

  • #2
    Re: Find Lowest value

    Use the SQL scalar function in composition with embedded SQL:

    Code:
    Exec SQL   Set :MinValue = Min(:Fld1, :Fld2, :Fld3, :Fld4, :Fld5);
    Birgitta

    Comment


    • #3
      Re: Find Lowest value

      Lowest_Field = Fld1;

      If Fld2 < Lowest_Field;
      Lowest_Field = Fld2;
      EndIf;

      If Fld3 < Lowest_Field;
      Lowest_Field = Fld3;
      EndIf;

      If Fld4 < Lowest_Field;
      Lowest_Field = Fld4;
      EndIf;

      If Fld5 < Lowest_Field;
      Lowest_Field = Fld5;
      EndIf;

      Fld6 = Lowest_Fld;

      Comment


      • #4
        Re: Find Lowest value

        Of course UserName10's code will work... and if it works, there's nothing really wrong with it... however.

        Fld6 = Fld1;

        If Fld2 < Fld6;
        Fld6 = Fld2;
        EndIf;

        If Fld3 < Fld6;
        Fld6 = Fld3;
        EndIf;

        If Fld4 < Fld6;
        Fld6 = Fld4;
        EndIf;

        If Fld5 < Fld6;
        Fld6 = Fld5;
        EndIf;

        Of course, my personal preference is Birgitta's method, as it only uses one program line. I personally like most anything that can be done in a single line, as to me it seems a bit cleaner... just my nickle's worth.


        WC

        Comment


        • #5
          Re: Find Lowest value

          you could also put the fields in an array and use SORTA opcode

          Comment

          Working...
          X