View Full Version : concatenate variable name
Hi experts
I defined some text-variables on project startup
text_a_1 = "abc";
text_a_2 = "def";
text_b_1 = "ghi"; and so on
then I defined on a page
V1 = "a";
V2 = 2;
disp = "text_"..V1.."_"..V2
Label.SetText("label1", disp);
and the result is: text_a_2 and not def
??????? HELP ??????????
mz241508
03-21-2007, 12:46 PM
Hi experts
I defined some text-variables on project startup
text_a_1 = "abc";
text_a_2 = "def";
text_b_1 = "ghi"; and so on
then I defined on a page
V1 = "a";
V2 = 2;
disp = "text_"..V1.."_"..V2
Label.SetText("label1", disp);
and the result is: text_a_2 and not def
??????? HELP ??????????
Use this code:
Label.SetText("label1", text_a_2);
thanks for the tip, mz241508 but it doe's not solve my problem:
I want to concatenate the content of some variables to the name of a new variable and display the predefined content of the new variable in a label or paragraph object
a1 = "some text" (a2, b1, b2, ... are also predefined)
v1 = "a"
v2 = 1
new_var = ?? v1..v2 ?? -- should be a1 and Label.SetText("label1", new_var); should display "some text"
RizlaUK
03-21-2007, 01:41 PM
its because you have the var in quotes, when concentrating vars do not wrap then in quotes as thay are treated as text by ams
a1="text1"
a2="text2"
a3="text3"
Label.SetText("label1", a1..a2..a3); = text1text2text3
or if you want a space between them
a1="text1"
a2="text2"
a3="text3"
Label.SetText("label1", a1.." "..a2.." "..a3); = text1 text2 text3
Hi experts...
You can not do that since your output is string and not a variable. Use tables for purposes like this:
text={}
text["a"]={}
text["a"][1]="abc";
text["a"][2]="def";
text["b"]={}
text["b"][1]="ghi";
V1 = "a";
V2 = 2;
disp = text[V1][V2]
Label.SetText("label1", disp);
Thank's bule
it's a good idea to use tables, but i fixed the problem in the meantime with a global function where i put all my if - then - else structure and the text strings (so i have to type it only one's) and on the pages where i need the text:
Label.SetText("label1", setBtxt(v1,v2)); setBtxt is the global function.
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.