question

Ankur A3 avatar image
0 Likes"
Ankur A3 asked Kavika F commented

Replace Label Text Error

Hi Team,

I want to make changes in the label name. I am trying it using string functions.

There is an error while writing code. Can anybody help me what is wrong in this code?

Thank you!

1651451086326.png

FlexSim 21.0.10
labelchangename
1651451086326.png (22.3 KiB)
· 1
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Kavika F avatar image Kavika F ♦ commented ·

Hi @Ankur A3, was Felix Möhlmann's answer helpful? If so, please click the "Accept" button at the bottom of their answer. Or if you still have questions, add a comment and we'll continue the conversation.

If we haven't heard back from you within 3 business days we'll auto-accept an answer, but you can always unaccept and comment back to reopen your question.

0 Likes 0 ·

1 Answer

·
Felix Möhlmann avatar image
0 Likes"
Felix Möhlmann answered

You have a duplicate variable. The string "labelName" is already part of the default parameters (line 6, the name of the label the activity is setting).

Variables have to be unique when in the same scope. Smaller scopes (such as if-conditions or for-loops) will inherit any variables that were declared in a larger scope, but not the other way around.

Either choose a different name of your string variable or remove the "string" part, to just assign a new value to the existing variable instead of declaring a new one.

int number = 3;
if(condition)
{
   double sum = 5 + number;   // this works
}
int number = 3;
if(condition)
{
   double sum = 5 + number;
}
if(other_condition)
{
   double sum = 7 - number;   // this works, because the "sum" variables are in separate scopes
}
if(condition)
{
   int number = 3; 
}
double sum = 5 + number;   // this does not work
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.