1

I am new to progress and I am trying to figure out how to get this working. My task is to Get a list of integer values from user as semi colon separated and message the highest and lowest value on that list. Till now I have used an entry function to help me get just the integers entered by the user one after another. like so

repeat I = 1 to  totalEntries:
    m = entry (I, Userinput, ";").
    display m. 
end.

After this I would like to find out the maximum value of all the entries. how can I do this since maximum function accepts more than one value for comparison.

Tom Bascom
  • 13,405
  • 2
  • 27
  • 33
nikita
  • 31
  • 7

2 Answers2

1

There is no built in function to give a maximum or minimum number from given list of numbers. You need to write your own logic as in most of the programming languages. Here is an example:

DEF VAR i     AS INT.
DEF VAR nlist AS CHAR INIT "1;2;7;3;6;9".

DEF VAR imin  AS INT.
DEF VAR imax  AS INT.

imin = INTEGER(ENTRY (1, nlist, ";")).
imax = INTEGER(ENTRY (1, nlist, ";")).

REPEAT i = 2 TO  NUM-ENTRIES(nlist, ";"):

    IF INTEGER(ENTRY(i, nlist, ";")) > imax THEN
        imax = INTEGER(ENTRY(i, nlist, ";")).

    IF INTEGER(ENTRY(i, nlist, ";")) < imin THEN
        imin = INTEGER(ENTRY(i, nlist, ";")).

END.

MESSAGE imax.
MESSAGE imin.
Austin
  • 1,237
  • 1
  • 11
  • 22
  • define variable numberEntry as character view-as fill-in no-undo. – nikita May 05 '15 at 13:02
  • Hey Austin, thanks for the reply however I have double checked and there is a function called Maximum, please find the code below. This is my entire procedure that I have so far. Define variable NumberEntry as character view-as fill-in no-undo. Define variable UsersInput as character no-undo. Define variable i as integer no-undo. Define variable totalEntries as integer no-undo. Define variable m as character no-undo. Define variable n as character no-undo. Define button bFind. – nikita May 05 '15 at 13:22
  • Define frame main numberEntry label “Enter numbers separated by semi colon” skip bFind label “Find Max and Min” with side-labels. /*Trigger for button*/ On choose of bFind in frame main do: /*Retrieve the users input*/ Usersinput = (numberEntry :screen-value). /*to find out how many characters the user has enterd.*/ totalEntries = num-entries(UsersInput, ‘;’). Display totalentries. /*Logic to extract Users input values one by one.*/ Repeat i = 1 to totalEntries: M = entry(i, UsersInput, “;”). Display m. End. /*Logic to find the maximum element. */ ..... end. – nikita May 05 '15 at 13:23
  • The maximum function won't work on a list of entries. It works like this: MAXIMUM(1,2,3) will return 3. So NOT MAXIMUM ("1,2,3") – Jensd May 05 '15 at 18:05
0

As Austin sad, there is no built-in function in Progress to give a maximum or minimum number from a list.

In your comment, you've mentioned that MAXIMUM(1,2,3) worked. Yes, it works, but you have to figure that you're passing three parameters to the function, not a list of numbers inside a single CHAR variable.

To solve your problem you can use the solution given by Austin or you can use two functions that receive a CHAR variable with semi colon separated values and return maximum or minimum values.

Here is an example, based on your code.

FUNCTION iMax RETURNS INTEGER
    ( INPUT pData AS CHAR ):

    DEF VAR iOutput     AS INT  NO-UNDO.
    DEF VAR iCount      AS INT  NO-UNDO.

    iOutput = ?.

    DO iCount = 1 TO NUM-ENTRIES(pData,';'):
        IF iOutput = ? THEN DO:
            iOutput = INT(ENTRY(iCount,pData,';')).
            NEXT.
        END.
        iOutput = MAX(iOutput,INT(ENTRY(iCount,pData,';'))).
    END.

    RETURN iOutput.

END FUNCTION.

FUNCTION iMin RETURNS INTEGER
    ( INPUT pData AS CHAR ):

    DEF VAR iOutput     AS INT  NO-UNDO.
    DEF VAR iCount      AS INT  NO-UNDO.

    iOutput = ?.

    DO iCount = 1 TO NUM-ENTRIES(pData,';'):
        IF iOutput = ? THEN DO:
            iOutput = INT(ENTRY(iCount,pData,';')).
            NEXT.
        END.
        iOutput = MIN(iOutput,INT(ENTRY(iCount,pData,';'))).
    END.

    RETURN iOutput.

END FUNCTION.

/****************/

Define variable NumberEntry as character view-as fill-in no-undo. 
Define variable UsersInput as character no-undo. 
Define variable i as integer no-undo. 
Define variable totalEntries as integer no-undo. 
Define variable m as character no-undo. 
Define variable n as character no-undo. 
Define button bFind. 
Define frame main numberEntry label "Enter numbers separated by semi colon" skip 
    bFind label "Find Max and Min" with side-labels. /*Trigger for button*/ 
On choose of bFind in frame main do: /*Retrieve the users input*/ 
    Usersinput = (numberEntry:screen-value). /*to find out how many characters the user has enterd.*/ totalEntries = num-entries(UsersInput,';'). Display totalentries. /*Logic to extract Users input values one by one.*/ 
    Repeat i = 1 to totalEntries: M = entry(i, UsersInput, ";"). 
        Display m. 
    End. /*Logic to find the maximum element. */ ..... 
    MESSAGE 'MAXIMUM :' iMax(UsersInput) SKIP 
            'MINIMUM :' iMin(UsersInput)
        VIEW-AS ALERT-BOX INFO BUTTONS OK.
END.

VIEW FRAME main.
ENABLE ALL WITH FRAME main.
WAIT-FOR CHOOSE OF bfind.

You can call iMax() or iMin() and get MAX or MIN values from Progress MAXIMUM and MINIMUM function using a CHAR list of INTEGER values separated by semi colons without need to make a full code block to do the comparision and get the information for each situation that presents necessary.

Hope it helps.

Bruno
  • 102
  • 1
  • 6