dynamic formating

defreeman

New Member
Is there a way to have dynamic formating in a frame

Here is an example of what I am trying to do
-------------------------------------------------------------------
def var p-desc as char.
def var h-desc.

form
p-desc at 32 format "x(8)" space(0) h-desc skip
with side-labels center row 1 frame mainf
title " Customer Maintenance ".

main:
.
.
.
if customer.country = "USA" then
p-desc = "1"
else
p-desc = "011-" + country.p-code + "-"

display p-desc with frame mainf.
update h-desc with frame mainf.
-------------------------------------------------------------------
but instead of having the format "x(8)" for p-desc I would rather it
have a format of "x(length(p-desc))"

what would be a means or syntax of doing this?

Thanks,

Dave
 
I know for a fact my desc field will be no more than 8 characters.

What I am trying to avoid is having only spaces between the two
variables on the display. I can do this by front loading the first
char with spaces but it doesnt look right.

if I left it alone it would look like this

011-44- 555-555-1234

front loaded it looks like this
.011-44-555-555-1234

I would like for it to be like this
011-44-555-1234

This way if I have a US phone number(for which we don't need to dial 011)
it will look like this
......1-555-555-1234
instead of
1-555-555-1234

put spaces where the .'s are
 
Yes, you can change the format by using the format attribute of the widget.

So in your case:
Code:
DISPLAY p-desc WITH FRAME mainf.
p-desc:FORMAT IN FRAME mainf = "x(":U + STRING(LENGTH(p-desc)) + ")":U.
But you will also have to re-position the field (move it to the right a little). You can try to do that with the X or COLUMN attributes (X in pixels and COLUMN in characters). I suppose the end result depends on whether you are using GUI or CHUI.
 
understanding the question or that spaghetti code
was the hard part, no offence :)

i gather you're looking to change the format
according to the country code, right ?

here's a short sample

<snippet>

define var cCountryCode as char no-undo init "US".
define var cPhoneNum as char no-undo.


form
cCountryCode
cPhoneNum
with frame a width 80 1 columns side-labels.




/* set cPhoneNum format event */

on "leave" of cCountryCode
or "entry" of frame a do:


cPhoneNum:format =
( if cCountryCode:screen-value = "us" then
"9-999-999-9999"
else "999-999-999-9999" ).




/* you can also change it's position
* for example to right align with cCountryCode


cPhoneNum:column =
( cCountryCode:column + cCountryCode:width )
- cPhoneNum:width. */


end. /* leave of cCountryCode */

update
cCountryCode
cPhoneNum
with frame a.

</snippet>

the entire user interface can be created or changed
dynamically at run-time

though it leaves out some of the elegance of 4gl
having to specify everything explicitly
usually a mix of both is a good way to go

note that some properties can't be changed after the widget ( ui object )
has been viewed or more to the point realized
i.e. turned from data to the actual windows widget

i highly recommend reading the chapter on
dynamic graphical objects
in the progress 4gl handbook in your edocs
2 hours, that's all it takes, and you'll be an expert on the subject

joey jeremiah, degrassi
 
Hey thanks guys,

Sorry about the confusion in the question. I tried creating a snippit of my main code so it would not distract. The reason I broke the phone into two parts was so the first part (011-{country code}-) would be created and just displayed the other part was going to allow the user to update the remaining portion of the phone number.

I populated the country code after the user had updated the mailing address and I "knew" what country was in question. The problem is the address, phone numbers, and contact information is in the same frame (chui) so the object is created long before I will know which is the proper format.

I have tried using &GLOBAL-DEFINE with no luck like this
----------------------------------------------------------------------
&GLOBAL-DEFINE CPHONE-FMT xxxxxxxx

form
p-desc at 32 label "Telephone" format "x({&CPHONE-FMT})" space(0) h-desc no-label skip
with side-labels center row 1 frame mainf
title " Customer Maintenance ".

&GLOBAL-DEFINE CPHONE-FMT xx
display p-desc with frame mainf.
-----------------------------------------------------------------------

The result of this experiment was the format used 8 characters for the display. now if i didn't create the form until AFTER the 2nd global define then it used 2 characters in the display.

I tried the earlier suggestion

def var p-desc as char.
def var h-desc as char.
form
p-desc label "Telephone" space(0) h-desc no-label skip
with side-labels center row 1 frame mainf
title " Customer Maintenance ".
p-desc = "001-44-".
h-desc = "555-555-1234".
DISPLAY p-desc
h-desc WITH FRAME mainf.
p-desc:FORMAT IN FRAME mainf = "x(":U + STRING(LENGTH(p-desc)) + ")":U.
(pretty sure my spaces will be stripped sorry)

and that display was also 8 characters. I have a feeling that once the object frame is created that there is not a way of dynamically reformating the p-desc object.
 
the problem is we can't understand your question
describe it in one statement not one page

if you want to change to format according to the country code
cut and paste the sample i wrote

it works regardless of gui or chui
i've already checked it in both cases ( win xp, oe10b )


you're also mixing compile-time and run-time statements

compile-time statements like preprocessors
execute while the program is compiling
for example which code to compile
depending on version or operation system or user interface etc.

not while the program is running
like you tried to do as part of the format definition

like the name implies, makes sense right ?


joey jeremiah, degrassi
 
I'll give that a try Joey and I want you to know how much I appriciate the non-agressive and mutually respectful interaction that has developed for the exchange of ideas.
 
Hey no worries and no hard feelings at all

and BTW you ROCK!! That code worked like a champ I don't have a copy of the edoc's you mentioned. Any advice for a Progress newbie as to where to download a copy?
 
no, you rock man !!!


psdn.com is the main resource center for us developers

you can download all the docs, 50 somewhat books
for free of course

web events, sort of, video based training / presentations
theres 2-3 new ones a month

news, tech papers etc.
it might be alot to take in at first


the progress knowledge base is also an amazing resource
solutions, how-tos, undoc features etc.

i hate to admit it, but it's also worth subscribing to peg.com
enough said.
 
Back
Top