Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register

Change the type of variable (protected or public) with a if condition

Change the type of variable (protected or public) with a if condition

Hello everyone,

I would like to know if it's possible to use a boolean to change the type protected or not of a bus?

I tried this code:

  DataCoach3D dataCoach3D(ModeProtectedActivated=ModeProtectedActivated)
    annotation (Placement(transformation(extent={{40,50},{60,70}})));
  public
  parameter Boolean ModeProtectedActivated=false;
 
    if Boolean ModeProtectedActivated then
    { protected Modelica.Icons.SignalSubBus signalSubBus annotation (Placement(transformation(extent={{-32,58},{-12,78}})))";"}
  [else
  { public Modelica.Icons.SignalSubBus signalSubBus annotation (Placement(transformation(extent={{-32,58},{-12,78}})))";"}
    ]
    end if ;



But it sent me back the following syntax error:

Error: declaration window line 16 column 5, syntax error at "if" missing { "end" "external"   }
Error: declaration window line 17 column 7, syntax error at "protected" missing "end" and missing ";" and missing EndOfFile
ERROR: 2 errors were found


Thanks you for your help and have a nice day.

Edited by: tomtom451 - Apr-04-16 13:33:57

Re: Change the type of variable (protected or public) with a if condition

Modelica does not allow to change public/protected on a boolean variable.

Re: Change the type of variable (protected or public) with a if condition

Thank you,

But it is possible to change the type of the variable easily?
because we have a lot of bus and we want to be able to put them all in protected on one click to hide some informations.

Edited by: tomtom451 - Apr-04-16 14:07:16

Re: Change the type of variable (protected or public) with a if condition

Code:

model M

protected
  extends OtherModel; // Makes everything in OtherModel protected
end M;

There are 0 guests and 0 other users also viewing this topic
You are here: