' Demostration of Rapid-Q's infinite parameter passing feature by William Yu
' Function FindMax takes a list of number (up to 255 parameters) and
' returns the largest number.


$APPTYPE GUI

DECLARE SUBI PRINTF (...)
DECLARE FUNCTIONI FindMax (...) AS DOUBLE


PRINT "The largest number is: "; _
      FindMax(234, 98.23, 54, 2, FindMax(324, 1045.2999, 24, 129), 100, 945.3, -0.34)

PRINT "The largest number is: "; FindMax(10, 99, 30, 44, 150, 15, -9832498)
PRINT "The largest number is: "; FindMax(100, 10)
PRINT "The largest number is: "; FindMax(99)

PRINTF "The largest number is: %d %d\n", FindMax(100, 200, 99, 30), FindMax(10, 99, 30, 44, 150, 15, -9832498)




SUBI PRINTF (...)
  DIM I AS INTEGER
  DIM N AS INTEGER
  DIM M AS INTEGER

  N = 1   ' Number count
  M = 2   ' String count

  FOR I = 1 TO LEN(ParamStr$(1))
    IF MID$(ParamStr$(1), I, 1) = "%" THEN
      I = I + 1
      IF LCASE$(MID$(ParamStr$(1), I, 1)) = "d" THEN
        PRINT ParamVal(N);                        ' Use this to print number
        N = N + 1
      ELSEIF LCASE$(MID$(ParamStr$(1), I, 1)) = "s" THEN
        PRINT ParamStr$(M);                       ' Strings stored here
        M = M + 1
      ELSE
        PRINT MID$(ParamStr$(1), I-1, 2);        
      END IF
    ELSEIF MID$(ParamStr$(1), I, 1) = "\" THEN
      I = I + 1
      IF LCASE$(MID$(ParamStr$(1), I, 1)) = "n" THEN
        PRINT
      ELSE
        PRINT MID$(ParamStr$(1), I-1, 2);        
      END IF
    ELSE
      PRINT MID$(ParamStr$(1), I, 1);
    END IF
  NEXT
END SUBI


FUNCTIONI FindMax (...) AS DOUBLE

  DIM Largest AS DOUBLE
  DIM I AS BYTE

  Largest = -999999999999

  FOR I = 1 TO ParamValCount
    IF ParamVal(I) > Largest THEN
      Largest = ParamVal(I)
    END IF
  NEXT

  Result = Largest
END FUNCTIONI
