Using frames in progress 4gl - progress-4gl

Can anyone help me understand how to display the following pattern using a Progress 4gl frame:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5.
I have tried like this:
DEFINE VARIABLE a AS INTEGER NO-UNDO.
DEFINE VARIABLE b AS INTEGER NO-UNDO.
DO
a =1 TO 5 WITH FRAME f:
DO
b = 1 TO a WITH FRAME f:
DISPLAY a SPACE SKIP.
PAUSE.
END.
END.
/* while displaying the answer is overwritten, how do I display the answer side by side? */

If you were sending your output to a file you could do it like this:
define variable a as integer no-undo.
define variable b as integer no-undo.
output to "output.txt".
do a = 1 to 5:
do b = 1 to a:
put b.
end.
put skip.
end.
output close.
Using DISPLAY and FRAME is not like text files or printers. When you create a frame and DISPLAY "A" in it you are defining a single position where the variable will be displayed.
Every time that you DISPLAY A the value will be placed in the same position.
You can make it a DOWN frame and move to a new line with each iteration of the outer loop but you will still only have one position per line.
define variable a as integer no-undo.
define variable b as integer no-undo.
do a = 1 to 5 with frame f:
do b = 1 to a:
display b with frame f.
end.
down with frame f.
end.
To have multiple positions you need multiple variables or an array or you can build a string (doydoy44's solution). Here is an example with an array:
define variable a as integer no-undo.
define variable b as integer no-undo.
define variable c as integer no-undo extent 5 format ">>>>".
do a = 1 to 5 with frame f:
do b = 1 to a:
c[b] = b.
end.
display c with frame f.
down with frame f.
end

I'm not sur to understand what is the problem.
May be this can help you:
DEFINE VARIABLE a AS INTEGER NO-UNDO.
DEFINE VARIABLE b AS INTEGER NO-UNDO.
DEFINE VARIABLE woutput AS CHARACTER NO-UNDO.
DO
a =1 TO 5 WITH FRAME f:
woutput = "".
DO
b = 1 TO a WITH FRAME f:
woutput = woutput + " " + string(b).
END.
DISPLAY TRIM(woutput) SKIP .
PAUSE.
END.

The behaviour you are talking about is what I call a down frame. ABL creates a frame automatically for any output, and if you are displaying a series of records from a table, it knows to make that frame a down frame, for example:
for each customer no-lock:
display customer.
end.
But in your example you aren't using for each. To get the down frame behaviour you are going to have to make it happen yourself.
Here is the simplest code that will give you that:
def var v-i as int no-undo.
do v-i = 1 to 10 with down:
display v-i.
down.
end.
It's actually clearer what is going on, though, if you spell things out a bit further. Let's define a named frame, make it a down frame, and then use it:
def var v-i as int no-undo.
def frame f-x
v-i
with down.
do v-i = 1 to 10:
display v-i with frame f-x.
down with frame f-x.
end.
It's almost always worth defining a frame if you are outputting something, I find.

define variable a as int no-undo.
define variable b as int no-undo.
define variable res as char no-undo.
update a.
b = 1.
repeat while(b <= a):
res = res + " " + string (b).
b = b + 1.
disp res format "x(20)".
end.

Related

Progress 4GL - update

how can I check if update was successful when I run this For Each
FOR EACH products
WHERE products.name = "ProductsName":
update price = 1000.
END.
Sometimes this For Each is ok, but sometimes when record is lock it doesn't work. I need run this For Each via WebSpeed and return true when For Each is successful or false when not. How can I get this result?
You should add more details to your request, but try this it might help get you started:
procedure update_items:
define output parameter records_read as integer no-undo.
define output parameter records_updated as integer no-undo.
define output parameter records_locked as integer no-undo.
define buffer item for item.
define buffer item_update for item.
define variable retry_count as integer no-undo.
for each item no-lock:
accumulate 1 (total).
records_read = (accum total 1).
retry_count = 0.
repeat for item_update:
find item_update exclusive-lock
where rowid(item_update) = rowid(item)
no-wait no-error.
if locked item_update then do:
if retry_count > 5 then do:
records_locked = records_locked + 1.
leave.
end.
retry_count = retry_count + 1.
do on endkey undo, leave:
pause 3 no-message.
end.
undo, next.
end.
if not available item_update then do:
/*If that matters you can code for it too*/
leave.
end.
item_update.Price = 1000.
release item_update.
records_updated = records_updated + 1.
leave.
end.
end.
end.
define variable items_read as integer no-undo.
define variable items_updated as integer no-undo.
define variable items_locked as integer no-undo.
run update_items(output items_read,
output items_updated,
output items_locked).
display items_read items_updated items_locked with side-labels 1 col.

is it possible to use MaximumFuntion within an Entry Funciton in Progress 4gl

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.
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.
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.

Length of Array in progress?

Given two arrays, ( for example 1,2,3,4,5 and 2,3,1,0). Find which number of first array is not present in the second array. How can i get Length of Arrays in progress 4gl ?
If the object in question is an ARRAY, rather than a LIST, you use the EXTENT() function to determine the number of elements. Using arrays:
define variable a1 as integer no-undo extent 5 initial [ 1, 2, 3, 4, 5 ].
define variable a2 as integer no-undo extent 4 initial [ 2, 3, 1, 0 ].
define variable i as integer no-undo.
define variable j as integer no-undo.
define variable ok as logical no-undo.
do i = 1 to extent( a1 ):
ok = no.
do j = 1 to extent( a2 ):
if a1[i] = a2[j] then ok = yes.
end.
if ok = no then message a1[i] "is not in a2".
end.
To have the length of a list (number of items of the list), you can use NUM-ENTRIES() function.
To know if an item is present in a list, you can use LOOKUP() function.
So for your example, you can do something like this:
DEFINE VARIABLE wclist1 AS CHARACTER NO-UNDO INITIAL "1,2,3,4,5".
DEFINE VARIABLE wclist2 AS CHARACTER NO-UNDO INITIAL "2,3,1,0".
DEFINE VARIABLE wc-list-no-present AS CHARACTER NO-UNDO.
DEFINE VARIABLE wi-cpt AS INTEGER NO-UNDO.
/* For each items of list1 */
DO wi-cpt = 1 TO NUM-ENTRIES(wclist1, ","):
/* Test if the item is in list 2 */
IF LOOKUP(ENTRY(wi-cpt, wclist1, ","), wclist2, ",") = 0
THEN
wc-list-no-present = wc-list-no-present + "," + ENTRY(wi-cpt, wclist1, ",").
END.
/* TRIM is to remove the first "," */
DISPLAY TRIM(wc-list-no-present, ",").
def var a as int extent 5 initial [1,2,3,4,5] no-undo.
def var b as int extent 4 initial [2,3,1,0] no-undo.
def var i as int no-undo.
def var j as int no-undo.
loop:
repeat i = 1 to extent(a):
repeat j = 1 to extent(b):
if a[i] = b[j]
then next loop.
end.
Display a[i] "not in b array" format "x(20)".
end.

Progress 4GL: Labelling a field from a variable

I am having trouble labelling a field(s) on a frame. The number of fields and the required labels are determined at run-time.
the required labels are stored in char array:
w-indarray[]
I am using the following loop to add the required fields to the frame
do i = 1 to w-nooff:
form w-sstrings[i] with frame f1.
w-sstrings[i]:label in frame f1 = w-indarray[i].
end.
But I get an error:
Widget array-element requires constant subscript.
I have googled but the only occurrence looks slightly different and I'm not sure if the solution is applicable. http://www.mofeel.net/258-comp-databases-progress/5295a6889.aspx
I am assuming that being able to reference the elements of w-indarray[] as literals would resolve this as i could just do:
form w-sstrings[i] label "abc" with frame f1.
is there any way of referencing the elements of the w-indarray[] as literals that I am missing?
Thanks for your time.
You can do this without using static numbers for the extent by getting all widget handles and modifying their labels. It works but it's kind of a lot code to do something that really should be easier.
Something like this:
DEFINE VARIABLE cLabel AS CHARACTER NO-UNDO EXTENT 10 INIT ["One","Two","three","Four","Five","Six","Seven","Eight","Nine","Ten"].
DEFINE VARIABLE cField AS CHARACTER NO-UNDO EXTENT 10.
DEFINE VARIABLE hFieldGroup AS HANDLE NO-UNDO.
DEFINE VARIABLE hFirstWidget AS HANDLE NO-UNDO.
DEFINE VARIABLE iExtent AS INTEGER NO-UNDO.
DEFINE VARIABLE iLoop AS INTEGER NO-UNDO.
DEFINE FRAME f1 WITH SIDE-LABELS 1 COLUMN.
DISPLAY
cField
WITH FRAME f1.
/* Static will be done like this
Commenting out this
ASSIGN
cField[1]:LABEL = cLabel[1]
cField[2]:LABEL = cLabel[2]
cField[3]:LABEL = cLabel[3]
cField[4]:LABEL = cLabel[4]
cField[5]:LABEL = cLabel[5]
cField[6]:LABEL = cLabel[6]
cField[7]:LABEL = cLabel[7]
cField[8]:LABEL = cLabel[8]
cField[9]:LABEL = cLabel[9]
cField[10]:LABEL = cLabel[10].
*/
ASSIGN
hFieldGroup = FRAME f1:FIRST-CHILD
hFirstWidget = hFieldGroup:FIRST-CHILD.
/* Widget-loop. Could really be done prettier... */
REPEAT:
iLoop = iLoop + 1.
hFirstWidget = hFirstWidget:NEXT-SIBLING NO-ERROR.
IF hFirstwIDGET = ? THEN LEAVE.
IF hFirstWidget:TYPE = "FILL-IN" THEN DO:
iExtent = iExtent + 1.
/* Set dynamic label */
hFirstWidget:LABEL = cLabel[iExtent].
END.
END.
The error message says you need to use a constant in the array instead of a variable. This means you'll need to do a CASE statement to get the functionality you're looking for - like so:
CASE i:
WHEN 1 THEN w-sstrings[1]:label in frame f1 = w-indarray[i].
WHEN 2 THEN w-sstrings[2]:label in frame f1 = w-indarray[i].
WHEN 3 THEN w-sstrings[3]:label in frame f1 = w-indarray[i].
WHEN 4 THEN w-sstrings[4]:label in frame f1 = w-indarray[i].
WHEN 5 THEN w-sstrings[5]:label in frame f1 = w-indarray[i].
END CASE.
The reason for the constant array element is the compiler can't discern which field the array element corresponds to when you give it a variable designation.

setting a label after define

I have a display statement and I only display one of the values if a logical is true. How can I NOT display the label of the column (ie. blank)
def var one as char label "one" no-undo.
def var two as char label "two" no-undo.
def var three as char label "three" no-undo.
def var four as char label "four" no-undo.
def var logic as logi no-undo init no.
display
one
two
three
four when logic
with stream-io width 80.
define variable one as character no-undo initial "xyz".
define variable two as character no-undo initial "123".
define variable f as handle no-undo.
define variable h as handle no-undo.
form
one two
with frame a
.
f = frame a:handle.
if two = "" then
do:
h = f:first-child.
walk_tree: do while valid-handle( h ):
if h:name = "two" then
do:
h:label = "x".
leave walk_tree.
end.
h = h:next-sibling.
end.
end.
display
one two
with frame a
.
Easy Way:
def var a as char label "One" init "AAA".
def var b as char label "Two" init "BBB".
def var c as char label "three" init "CCC".
def var logic as logical init false.
form a b c with frame a no-underline.
if logic = false then c:label in frame a = "".
display a b c when logic with frame a.