User Variable Script Examples
Getting and setting the value of a user variable
JavaScript:
//language="JavaScript" var1 = GetUserVariable("MyUserVar1"); value = var1.Variable.Value; value = value + 1; result = value; resultunits = "m3"
or VBScript:
Dim var Set var = GetUserVariable("MyUserVar1") Dim value value = var.Variable.Value value = value + 1 result = value
Set the temperature of a stream three different ways
language="JavaScript"; Temperature.Value = 45; //Set a stream temperature in Celcius Temperature.SetValue(45,"C"); bd = MyBackDoor().BackDoorVariable(":Temperature.501.0").Variable; bd.value = 45; //'Set it via the back door
or VBScript:
Temperature.Value = 45 'Set a stream temperature in Celcius Temperature.SetValue 45,"C" Dim bd set bd = MyBackDoor.backdoorvariable(":Temperature.501.0").Variable bd.Value = 45 'Set it via the back door
Set the stream temperature using JavaScript instead of VBScript
language="JavaScript"; Temperature.SetValue(47,"C");
Dew point calculation
language="JavaScript"; if (MolarEnthalpyValue != -32767) //Make sure the stream has solved { myFluid = DuplicateFluid(); FS = myFluid.PVFlash(PressureValue, 1.0); if (FS == 0) //fsFlashOK { result = myFluid.Temperature.GetValue("C"); resultunits = "C"; } }
or VBScript:
if enthalpvalue <> -32767 then 'Make sure the stream has solved dim myFluid dim FS set myFluid = DuplicateFluid FS = myFluid.PVFlash(PressureValue, 1.0) If FS = 0 Then ' fsFlashOK result = myFluid.Temperature.GetValue("C") resultunits = "C" end if end if
Change the "Use Calibration Factors From" setting inside a DHTR reactor depending on the flow rate of the recycle stream
Dim doc Set doc = Application.ActiveDocument Dim recStream Set recStream = doc.GetObjectInCase("RecycleStream") massflow = recStream.MassFlow.GetValue("t/h") if massflow <> -32767 then 'Is the value known? Dim getFromObj if massflow > 100 then Set getFromObj = doc.GetObjectInCase(“Reactor A") else Set getFromObj = doc.GetObjectInCase("Reactor B") end if Dim bd Set bd = MyBackDoor Dim var Set var = bd.BackDoorVariable(":KHunitoperation.600").Variable if var.Object <> getFromObj then var.Object = getFromObj end if end if
Copy spreadsheet cells
dim acase, ss, i, c, cu, c2 set acase = application.activedocument set ss = flowsheet.operations.item("SPRDSHT-1") for i = 3 to 51 set c = ss.Cell("B" & i) cu = ss.Cell("B" & i).units application.trace cu, false set c2 = ss.cell("D" & i) c2.variabletype = -1 c2.cellvalue = c.cellvalue c2.variabletype = c.variabletype next
Get a spreadsheet cell value
language="JavaScript"; //Get hold of the spreadsheet. //If the spreadsheet is in the same flowsheet, do this: sprd = FlowSheet.Operations.Item("Economics"); //Or this: sprd = SimulationCase.GetObjectInCase("Economics"); value = sprd.Cell("A3").CellValue; //Set the result: result=value;
or VBScript:
'Get hold of the spreadsheet. Dim sprd 'if the spreadsheet is in the same flowsheet, do this: Set sprd = FlowSheet.Operations.Item("Economics") 'Or this: Set sprd = SimulationCase.GetObjectInCase("Economics") Dim value value = sprd.Cell("A3").CellValue 'Set the result: result=value