I want to read a content of a string variable that represents several variables with a substring
Deklaration of strings:
addGlobal("sCLI80_1_Br_Short",STRING_VAR);
addGlobal("sCLI80_1_Br_Long",STRING_VAR);
addGlobal("sCLI80_2_Br_Short",STRING_VAR);
addGlobal("sCLI80_2_Br_Long",STRING_VAR);
addGlobal("sCLI80_3_Br_Short",STRING_VAR);
addGlobal("sCLI80_3_Br_Long",STRING_VAR);
addGlobal("sCLI80_4_Br_Short",STRING_VAR);
(could be local variables if using in the same modul)
CLI80_1, Cli80_2, ... is the substring
The variable is put together like:
string sSubString = "CLI80_1"
"s" + sSubString + "_Br_Short"
Now I would like read the Content of the variable "sCLI80_1_Br_Short" in sResultText
dpGet("s" + sSubString + "_Br_Short", sResultText);
But dpGet seems to be working only with systemvariables like System1:Global.BrigSc_Var.._value
How can I read the contents of a string variable with a composite variable ?
dynamic composite variable
- leoknipp
- Posts:2928
- Joined: Tue Aug 24, 2010 7:28 pm
Re: dynamic composite variable
Does "s" + sSubString + "_Br_Short" represent the name of a datapoint element?
The string which is passed to the dpGet() function must fit a dp element.
E.g. the following code works:
main()
{
string sDp;
float fValue;
sDP = ""xampleDP_Arg1.";
dpGet(sDp,fValue);
DebugTN("value",fValue);
}
Best Regards
Leopold Knipp
Senior Support Specialist
The string which is passed to the dpGet() function must fit a dp element.
E.g. the following code works:
main()
{
string sDp;
float fValue;
sDP = ""xampleDP_Arg1.";
dpGet(sDp,fValue);
DebugTN("value",fValue);
}
Best Regards
Leopold Knipp
Senior Support Specialist
- marcel.gay@wimag.ch
- Posts:62
- Joined: Thu May 07, 2015 6:55 pm
Re: dynamic composite variable
The varname of the datapointelements are for example
addGlobal("sCLI80_1_Br_Short",STRING_VAR);
addGlobal("sCLI80_1_Br_Long",STRING_VAR);
addGlobal("sCLI80_2_Br_Short",STRING_VAR);
etc.
If the var sSubString = "CLI80_1* the varname correspond to "sCLI80_1_Br_Short" with "s" + sSubString + "_Br_Short"
My variable isn't a datapointelement, what is the solutation ?
do I have to generate a datapointelement variable (like: dpGet("System1:Global.BrigSc_Var.._value", sVar);?
addGlobal("sCLI80_1_Br_Short",STRING_VAR);
addGlobal("sCLI80_1_Br_Long",STRING_VAR);
addGlobal("sCLI80_2_Br_Short",STRING_VAR);
etc.
If the var sSubString = "CLI80_1* the varname correspond to "sCLI80_1_Br_Short" with "s" + sSubString + "_Br_Short"
My variable isn't a datapointelement, what is the solutation ?
do I have to generate a datapointelement variable (like: dpGet("System1:Global.BrigSc_Var.._value", sVar);?
- marcel.gay@wimag.ch
- Posts:62
- Joined: Thu May 07, 2015 6:55 pm
Re: dynamic composite variable
I definde my Global variables with "addGlobal("sCLI80_1_Br_Short",STRING_VAR) ..................." in the initalize script of the Main Window (root Window, first started panel)
How I get the content in any other scripts ? Is this with dpGet possible ?
How I get the content in any other scripts ? Is this with dpGet possible ?
- gschijndel
- Posts:376
- Joined: Tue Jan 15, 2019 3:12 pm
Re: dynamic composite variable
Perhaps you could store your variables in a mapping, that would allow the dynamic variable name usage more easily.
- leoknipp
- Posts:2928
- Joined: Tue Aug 24, 2010 7:28 pm
Re: dynamic composite variable
If you do addGlobal("sCLI80_1_Br_Short",STRING_VAR); you just have define the variable.
Then you can use the variable in any script similar to variables define in the script itself in the same manager.
E.g.
sCLI80_1_Br_Short = "Hello":
Then the value "Hello" is saved in the global variable.
Best Regards
Leopold Knipp
Senior Support Specialist
Then you can use the variable in any script similar to variables define in the script itself in the same manager.
E.g.
sCLI80_1_Br_Short = "Hello":
Then the value "Hello" is saved in the global variable.
Best Regards
Leopold Knipp
Senior Support Specialist
- marcel.gay@wimag.ch
- Posts:62
- Joined: Thu May 07, 2015 6:55 pm
Re: dynamic composite variable
I MUST composite the var-name: "s" + sSubString + "_Br_Short"
Declaration is as you say existing ................ ('ve total > 500 var-names)
....
addGlobal("sPDL_2_Ls_Short",STRING_VAR);
addGlobal("sPDL_2_Ls_Long",STRING_VAR);
addGlobal("sPDL_3_Ls_Short",STRING_VAR);
addGlobal("sPDL_3_Ls_Long",STRING_VAR);
sCLI80_1_Br_Short = "CLI80 ARZ sect.1 sc101";
sCLI80_1_Br_Long = "clignoter et vitesse 80 Arzilier sect.1 Di Brigue (+) 101";
sCLI80_2_Br_Short = "CLI80 ARZ sect.2 sc102";
sCLI80_2_Br_Long = "clignoter et vitesse 80 Arzilier sect.2 Di Brigue (+) 102";
...
Then I've a tree-widgets following script where i'm add/delete danamic elements:
EP_BZ_On(string dp1, string sc) <- here I get the string-variable as argument (like: CLI80_1)
{
string sTmp, sTxt1, sTxt2, sVar ;
sTmp = "#" + sc ;
sTxt1 = "s" + sc + "_Br_Short" ; <--- here I compose the dynamic variable 1 (Text for the tree-element)
sTxt2 = "s" + sc + "_Br_Long" ; <--- here I compose the dynamic variable 2 (Text for the tool-tip)
TREE_BZ_BRIG.appendItem("SELECT_1", "#CLI80_1", sTxt1); <- here I would show the text in the tree element
TREE_BZ_BRIG.setToolTip("#CLI80_1", 0, sTxt2); <- here I would show the text in a tool tip
TREE_BZ_BRIG.setBackColor("#CLI80_1", 0 ,"{210,227,237}");
}
EP_BZ_Off(string dp1, string sc)
{
TREE_BZ_BRIG.removeItems(sc);
//dpSet("System1:Global.BrigScOff", "");
}
In this solutation the text isn't showing but the varname (see picture below)
Declaration is as you say existing ................ ('ve total > 500 var-names)
....
addGlobal("sPDL_2_Ls_Short",STRING_VAR);
addGlobal("sPDL_2_Ls_Long",STRING_VAR);
addGlobal("sPDL_3_Ls_Short",STRING_VAR);
addGlobal("sPDL_3_Ls_Long",STRING_VAR);
sCLI80_1_Br_Short = "CLI80 ARZ sect.1 sc101";
sCLI80_1_Br_Long = "clignoter et vitesse 80 Arzilier sect.1 Di Brigue (+) 101";
sCLI80_2_Br_Short = "CLI80 ARZ sect.2 sc102";
sCLI80_2_Br_Long = "clignoter et vitesse 80 Arzilier sect.2 Di Brigue (+) 102";
...
Then I've a tree-widgets following script where i'm add/delete danamic elements:
EP_BZ_On(string dp1, string sc) <- here I get the string-variable as argument (like: CLI80_1)
{
string sTmp, sTxt1, sTxt2, sVar ;
sTmp = "#" + sc ;
sTxt1 = "s" + sc + "_Br_Short" ; <--- here I compose the dynamic variable 1 (Text for the tree-element)
sTxt2 = "s" + sc + "_Br_Long" ; <--- here I compose the dynamic variable 2 (Text for the tool-tip)
TREE_BZ_BRIG.appendItem("SELECT_1", "#CLI80_1", sTxt1); <- here I would show the text in the tree element
TREE_BZ_BRIG.setToolTip("#CLI80_1", 0, sTxt2); <- here I would show the text in a tool tip
TREE_BZ_BRIG.setBackColor("#CLI80_1", 0 ,"{210,227,237}");
}
EP_BZ_Off(string dp1, string sc)
{
TREE_BZ_BRIG.removeItems(sc);
//dpSet("System1:Global.BrigScOff", "");
}
In this solutation the text isn't showing but the varname (see picture below)
- leoknipp
- Posts:2928
- Joined: Tue Aug 24, 2010 7:28 pm
Re: dynamic composite variable
What you have observed is the correct behaviour in WinCC OA.
You cannot access the values of global variables in that way.
As suggested by Gertjan you can use a mapping where the key is the variable name. Then you can build your key names during runtime and read the value for this key from the mapping.
Best Regards
Leopold Knipp
Senior Support Specialist
You cannot access the values of global variables in that way.
As suggested by Gertjan you can use a mapping where the key is the variable name. Then you can build your key names during runtime and read the value for this key from the mapping.
Best Regards
Leopold Knipp
Senior Support Specialist
- marcel.gay@wimag.ch
- Posts:62
- Joined: Thu May 07, 2015 6:55 pm
Re: dynamic composite variable
mapping would be a nice solution, but it doesn't fit with addglobal() and I need the var Globaly
- leoknipp
- Posts:2928
- Joined: Tue Aug 24, 2010 7:28 pm
Re: dynamic composite variable
You can define the variable in a CTRL library which is loaded by the UI with the keyword "global".
Then you have a manager global variable.
Best Regards
Leopold Knipp
Senior Support Specialist
Then you have a manager global variable.
Best Regards
Leopold Knipp
Senior Support Specialist