Dynamic Assign Statement?

jennid

Member
Hello-A new programmer here asked me a question and I want to make sure there isn't a way to do this that I am missing. I know how to create dymanic queries...is it possible to create dynamic assign statements?

Example (a very simple one...our real life scenario is more complex)

A window has two fill-in widgets. One is called "name1" and one is called "name2".

In one scenario we want to update name1. If other conditions exist, then name2 is to be updated.

Without some sort of dynmaic way to build the assign statement, we'd have code like:

if conditionA = true then
assign name1:screen-value = "valueA".
else if conditionB = true then
assign name2:screen-value = "valueB".

Is there a way to dynamically create our assign statement...something like:

def var v-widgetname as c no-undo.
assign v-widgetname = if conditionA = true then "name1"
else "name2".


Again, this is a very watered down version of our real-life scenario....I realize in the simple example above, building the assign statement wouldn't add much value.

I've hit the archived discussions here and did a lot of searching around on the knowledge base, but so far didn't find anything like this. Before I tell our green programmer that there is no way to do this, I want to make sure I'm not missing something obvious.

Thanks.
 

jennid

Member
The goal is to replace 20 separate assign statements and 20 other repetitive pieces of code throughout the program.

Current code is something like:
if conditionA then then assign name1:Screen-value = "ABC".
else
if conditionB then assign name2:screen-value = "EFG".
else
if conditionC then assign name3:screen-value = "124".
etc...

He was wondering if you could replace that with
assign v-widgetname:screen-value = v-datavalue.
 

tamhas

ProgressTalk.com Sponsor
Aren't you going to need just as many IF statements to set v-widgetname and v-data as it takes to do the actual assign?
 

jennid

Member
Not really.

First of all, I have to explain that the screen we are modifying is part of a menu that came with our ERP system. It's a
smart viewer. Due to how the menu was set up by the software provider, we have to use a smart viewer for it to work with
how the menu is set up. For each product in our warehouse, there are different quantities the item could be packaged in
(ie pack of 10, 100, case, pallet, etc...). What we wanted to do was add a browser to this screen that shows the different
package quantities the product is available in. However, the appbuilder won't allow us to put a browser on a viewer. So
he put several fill-ins on the screen instead.

current code:
for each item_uom where item_uom.prodno = fiprod:screen-value no-lock:
v-count = v-count + 1.
if v-count = 1 then
assign boxwidget1:screen-value = string(item_uom.qty).
else if v-count = 2 then
assign boxwidget2:screen-value = string(item_uom.qty).
else if v-count = 3 then
assign boxwidget3:screen-value = string(item_uom.qty).
etc....
end.

new programmer asked if we could instead do:
for each item_uom where item_uom.prodno = fiprod:screen-value no-lock:
assign v-count = v-count + 1
v-widgetname = "boxwidget" + trim(string(v-count))
v-widgetname:screen-value = string(item_uom.qty).
end.

OR

for each item_uom where item_uom.prodno = fiprod:screen-value no-lock:
assign v-count = v-count + 1
v-widgetname = if v-count = 1 then boxwidget1
else if v-count = 2 then boxwidget2 etc...
v-widgetname:screen-value = string(item_uom.qty).
end.

Since I am training a new person, I don't want to say it "can't" be done without knowing that's true.
 

tamhas

ProgressTalk.com Sponsor
OK, *now* I think you have actually defined your problem. You can't solve it the way you were thinking, but it doesn't mean that there aren't better or worse ways of handling the requirement.

At this point, I am going to bow out since I don't know about AppBuilder issues and my inclination would be toward using a bit of dynamite and just doing it right from scratch.

It is possible you should start a new thread with the last post as the first one, so that people who might help don't skip over it because they know you can't have what you think you want.
 

RealHeavyDude

Well-Known Member
There are only two ways to reference an ABL widget:
  1. Hard code the name in your code - in which case you obviously can't use a variable that holds the name.
  2. Grab the handle and store it on a variable of type handle.
As you are talking about "smart viewer" do you mean the smart viewer which is part of the ADM (introduced with Progress V8 somewhere around 1994 and later was renamed to ADM1 when ADM2 came out) or do you mean the smart data viewer which is part of the ADM2/Dynamics (introduced with Progress V9 somewhere around 1998)?

If you are talking about the ADM1 I am afraid I can't give you any advice as I fiddled with this thing last time in 1995. If you are talking about the ADM2 one there might be easy solutions.

Nevertheless, you need to grab the handle to the widgets which you can achieve with a widget walk on the frame. As soon as you have the handle to a widget you may access its type and name attributes and branch your logic on this information. Be aware that the first child of a frame is a widget group. You must get the first child of the first child of the frame to actually access the first widget. From then on you can continue with next sibling.

Heavy Regards, RealHeavyDude.
 

RealHeavyDude

Well-Known Member
Then, I am afraid, that you are stuck with a widget walk on the frame that is on the smart viewer to grab the handles of the individual widgets.

Heavy Regards, RealHeavyDude.
 
Top