简体   繁体   中英

How to perform basic string handling in Progress

I want to put the whole alphabet in a string. For that, I need two variables, one containing the whole alphabet, the other containing a counter for the letters to be used, as follows:

DEFINE VARIABLE i AS INTEGER.
DEFINE VARIABLE Alphabet AS CHARACTER FORMAT "x(30)".

The logic I've found, does this as follows:

/* Main logic */
i = ASC("a").
REPEAT:
  APPLY CHR(i) TO Alphabet.
  IF CHR(i)="z" THEN LEAVE.
  i = i + 1.
END.

As I have experience in other programming languages, I would opt for another approach:

/* Main logic */
i = ASC("a").
REPEAT:
  Alphabet = Alphabet + CHR(i). /* This line is different */
  IF CHR(i)="z" THEN LEAVE.
  i = i + 1.
END.

Obviously my proposal is not working, but then I wanted to understand why, and I had a look at an official URL, explaining the APPLY statement , stating the following:

APPLY statement

Applies an event to a widget or procedure. Syntax

APPLY event [ TO widget-phrase ]

Now I'm lost: what is the relationship between chars in a string, and events (I understand an event as a button-click or something)? (I fear I'm completely misunderstanding this whole concept)

Edit, after some more research:

In the meantime I've understood that I can make the whole thing work, as follows:

/* Main logic */
i = ASC("a").
REPEAT:
  Alphabet = Alphabet + CHR(i). /* This line is different */
  IF CHR(i)="z" THEN LEAVE.
  i = i + 1.
END.
Alphabet:SCREEN-VALUE = Alphabet.

This, however, only shows me that "normal" string-handling is possible in Progress, it does not yet explain the whole event -thing.

Variables in Progress actually have two parts: the normal variable part and the displayed part. When you assign a value to a variable it is only assigned to the variable part. If you want to assign a value only to the displayed part you assign it to yourvariable:screen-value. If you want to get the displayed value to the variable value you can say

assign yourvariable.

And if you want to display the variable value you say

display yourvariable.

Some keywords and functions apply to the displayed nature of variables. The example you have that uses APPLY does not work for me, but I guess the intent there was to simulate key-presses on a displayed variable - hence APPLY-ing each letter. Seems like a strange way of doing it.

Your last code sample makes most sense, though I would modify the last line as follows:

i = ASC("a").
REPEAT:
  Alphabet = Alphabet + CHR(i). /* This line is different */
  IF CHR(i)="z" THEN LEAVE.
  i = i + 1.
END.
display Alphabet.

Note that if you do not need to show a variable's value on a screen there is no reason to call DISPLAY.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM