Getting dynamically generated string value

ttgroup

New Member
Hopefully someone can help!
I have a number of already defined strings ie: abc1 abc2 abc3. I also have another string v-hold used to dynamically generate the string value ie: v-hold = "abc" then incrementing an integer to get one of the above predefined strings.
So basically,

def var abc1 as char no-undo.
def var abc2 as char no-undo.
def var abc3 as char no-undo.
def var v-hold as char no-undo.
def var I as int no-undo.

abc1 = "newstring".

do I = 1 to 3:
v-hold = "abc" + string(I).
display v-hold.
end.


How do I display the value of the dynamically generated string. In this case the value of "abc1" being "newstring".

Thanks
 
I think it will be simpler if you use temp-table instead. This will save you a lot of brain cramping.

/*def var abc1 as char no-undo.
def var abc2 as char no-undo.
def var abc3 as char no-undo.
*/
def temp-table tt1
field abc1 as char
field abc2 as char
field abc3 as char.

def var v-hold as char no-undo.
def var I as int no-undo.
def var bh as handle.
/*abc1 = "newstring".*/
create tt1.
assign abc1 = "newstring"
abc2 = "newstring2"
abc3 = "newstring3".

find first tt1.
bh = buffer tt1:handle.
do I = 1 to 3:
v-hold = "abc" + string(I).
disp bh:buffer-field(v-hold):buffer-value.
end.
 
Thanks, I'm not entirely familiar with using handles. What is the benefit for using the handle and buffer?

Thanks
Mark
 
In this case you get the name of the field at run time.
So I used to the dynamic buffer to get the value.
Otherwise you would have to write

disp tt1.abc1 abc2...
you cannot say tt1.v-hold

Buffer is just a pointer to that record and handle is the way to access that buffer.

-Parul.
 
Hi,

I couldnt understand ur problem xactly...
U can use something like key value pair as per ur requirement, temp table is a good one to use, but it consumes some amt of time if ur using like this, so u can jus go for usage of array to do this...

But the best practice is use something like key-value pair...
 
Back
Top