Showing results for 
Search instead for 
Do you mean 

Creating Failures via Simtalk

Hello All,


I am trying to create a failure across a few stations utilizing SimTalk. 


I am using a dialog box to retrieve the Name, Availability, and MTTR of a failure. I am then storing the name in a variable and creating a failure off of the information provided.


The problem I am having is that the variable cannot be used in an assignment statement for Availability or MTTR.


See the following code below:


tempName := FailureDialog.getValue("NameEditBox");


Station1.Failures.tempName.Availability := 95.00;

Station1.Failures.tempName.MTTR := str_to_time("1:00:00");


This code does not work as I get an error for an Unknown identifier for Failures.tempName.


Is there a way to assign Availability and MTTR to a specific failure in simtalk?


Thank you!


Re: Creating Failures via Simtalk

Station1.Failures.tempName addresses a Failure named "tempName". If the local variable 'tempName' contains the string "abc", you would have to write instead. So for your code to work, you first have to retrieve the just created failure like this:

local tempName : string := FailureDialog.getValue("NameEditBox");
local f := Station1.Failures.getFailure(tempName);

f.Availability := 95.00;
f.MTTR := str_to_time("1:00:00");

Re: Creating Failures via Simtalk

Thank you Michael!


That worked perfectly. 


Now, I have one more question:


I have this code in my reset method and so if I click reset twice, I get the error that the name already exists in the name scope of the object. This is because it is trying to create the same failure again. Is there an if statement or something that can ignore the createFailure call if the failure name already exists?


Thank you in advance!

Re: Creating Failures via Simtalk

[ Edited ]

have you tried

if Station1.Failures.getFailure("failureName") = VOID then
. end;