tom01
tom01

Reputation: 125

Progress 4GL: Regarding TRIM function

I am having trouble with a really simple issue, but can't find an answer online. I want to display a string without succeeding space characters, so using TRIM. In the actual program the length of the string is not known until runtime, so i can't set a specific "format" size.

def var w-test as char init "abcdefghijklm                " format "x(30)".
display trim(w-test).

gives me

┌────────┐
│abcdefgh│
└────────┘

so does using

trim(w-test, " ").

No doubt I am being silly, but does anyone have any thoughts?

Thanks for your time.

Upvotes: 1

Views: 5001

Answers (2)

Tom Bascom
Tom Bascom

Reputation: 14020

Why do you want to know the length of the trimmed string in order to set a format? And why are you trimming it at all? I suspect that you are confusing display format and string content or storage.

If, for instance, the root of your problem has anything to do with building a string out of parts (which would be one reason to be using the TRIM() function) then formats are irrelevant.

A display format is just that, a display format. You are allocating space on the screen (or in a report) to hold some maximum width of text. It doesn't impact storage, or anything like that.

Surely you have some idea of how much space you want to reserve on the screen for this data?

If it turns out to be less than the reserved width that isn't generally a problem.

You might also have some thoughts about what to do if the data is wider than that. Many times people do nothing if it is too wide -- the reserved width is displayed and the remainder truncated. But you could put an indicator on the screen and you could even make it scrollable:

define variable xtext as character no-undo format "x(250)" view-as fill-in size 10 by 1.

xtext = "the quick brown fox jumped over the lazy dog.".

update xtext "...".

On the other hand you could also create a fully dynamic screen. That will require you to create the frame widget and fill-in and work with their handles but it will also allow you to calculate whatever format you'd like:

define variable fr as handle no-undo.
define variable fi as handle no-undo.

create frame fr.
assign
  fr:width-chars = 50
  fr:height-chars = 5
  fr:title = "Dynamic Frame"
.

create fill-in fi.
assign
  fi:row = 2
  fi:column = 20
  fi:width-chars = 10
  fi:format = "x(3)"
  fi:screen-value = "abc123"
  fi:frame = fr
.

assign
  fr:visible = yes
  fr:hidden = no
.

pause.

(The point of making the format "x(3)" and the width 10 is just to show that you can set it to whatever you want...)

Upvotes: 1

Tim Kuehn
Tim Kuehn

Reputation: 3251

The default format for DISPLAY of a string is 8 chars, so what you're doing here

display trim(w-test).

is the same as:

display trim(w-test) FORMAT "X(8)".

To get more of the string to display, specify a longer format - like so:

display trim(w-test) FORMAT "X(15)".

Upvotes: 1

Related Questions