Strange formatting behaviour

Crittar

Member
Hi folks,

I wonder if anyone out there can help me:

Progress 9.1d CHui.

Consider the two following snippets of code:
Code:
/* Snippet 1 */

ASSIGN fmat = '"x(' + STRING(LENGTH(myvar)) + ')"'.

PUT STREAM mystream
myvar FORMAT fmat.
Code:
/* Snippet 2 */

PUT STREAM mystream
myvar FORMAT "x(50)".
Would you expect the two pieces of code above to provide the same (or at least very similar) output?

What I am finding is that:

Assume myvar contained the value 'test text' (without any quotes around it)

snippet 1 would produce an output of "test text" (with quotes)
snippet 2 would produce an output of test text (without quotes).

Does anyone out there know how I could make snippet 1 work without producing the code round the text?

Please, this is driving me crazy!!
 

MHotovec

Member
I've always been told that Progress will not allow us to use a variable the way you're trying to - and I've yet to be able to prove that statement wrong.
The best explanation I've heard as to WHY is because of our 'friend' the frame manager. It seems that when a code FIRST runs the frame manager whips through to see what frames are required and 'creates' them. Therefore it won't allow for on-the-fly formatting changes that could affect a frame layout.

I don't know if that's really THE answer - but hey it sounds good.

If you're trying to do what I THINK you are, maybe you could try "put stream s-out unformatted".
The 'unformatted' will cause progress to just send out (put out?) the actual characters that it finds with no trailing spaces at the end. Also, if you have a tendency to stuff 50 characters in a field formatted for 8, the 'unformatted' command will handle that also.

Good luck
Mark

Crittar said:
Hi folks,

I wonder if anyone out there can help me:

Progress 9.1d CHui.

Consider the two following snippets of code:
Code:
/* Snippet 1 */

ASSIGN fmat = '"x(' + STRING(LENGTH(myvar)) + ')"'.

PUT STREAM mystream
myvar FORMAT fmat.
Code:
/* Snippet 2 */

PUT STREAM mystream
myvar FORMAT "x(50)".
Would you expect the two pieces of code above to provide the same (or at least very similar) output?

What I am finding is that:

Assume myvar contained the value 'test text' (without any quotes around it)

snippet 1 would produce an output of "test text" (with quotes)
snippet 2 would produce an output of test text (without quotes).

Does anyone out there know how I could make snippet 1 work without producing the code round the text?

Please, this is driving me crazy!!
 

Crittar

Member
Mark,

Thankyou for the reply.

I have, however, in the meantime managed to sort out the problem.

If anyone is interested the solution is to modify snippet 1 to be:

Code:
ASSIGN fmat = 'x(' + STRING(LENGTH(myvar)) + ')'.

PUT STREAM mystream
  myvar		  FORMAT fmat.

The cause of the problem was that I was using a combination of double and single quotes where I only needed one set of quotes:

fmat is a string variable. The only way progress knows x(8) is a string is if you enclose it in quotes. Obvious with hindsight.

In case you are interested the reason I wanted this is because I am writing a program to generate an email with an html body which will be called from several places and I wanted the html to look tidy (and also to cope with the situation where more characters were passed than would fit in the format I specified for my variable).

Once again, thanks for your input, Mark.
 

MHotovec

Member
Good for you for figuring that out - I'm gonna steal that! ;)

It figures my answer would be too easy. I've seen some of your work around here and know that you're lightyears ahead of me. So most likely anything I'd think of you've already ruled out.

Of course, that won't keep me from trying again someday...
 

Crittar

Member
Many thanks for those kind words :blush1: but from past experience it rarely turns out that anyone is lightyears ahead of (or behind) anyone else... Just that we have each encountered and solved different problems. Sharing those solutions is what ProgressTalk is all about.
 
Top