A little brute force but you could do something like this.
Define a variable for the minimum value
MinVal: int := 32000;
IFVar1<>0THEN
  MinVal :=Min(MinVal,Var1);END_IFIFVar2<>0THEN
  MinVal :=Min(MinVal,Var2);END_IFIFVar3<>0THEN
  MinVal :=Min(MinVal,Var3);END_IFIFVar4<>0THEN
  MinVal :=Min(MinVal,Var4);END_IFIFVar5<>0THEN
  MinVal :=Min(MinVal,Var5);END_IF
If you put the values in an array, then you could loop through it in a FOR loop.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks, that almost worked. But I want the MinValue to be at 0 value until 1 or more of Val1-5 goes over 0, then i want MinValue to have that value...
Maybe I should start to look for a diffrent solution.
Iam making an elevator for school, and Ive added a second elevatorcar and I want the it to go down
to the lowest floor as soon as 1 of 5 variables becomes active. If the MinValue is 0 the elevator stops.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
MinValueNonZero :=0;FORindex:=1TO4
 IFElevatorBtn[index] >0THEN
 IFMinValueNonZero=0THEN
   MinValueNonZero :=ElevatorBtn[index];
 ELSE
  IFMinValueNonZero>ElevatorBtn[index] THEN
   MinValueNonZero :=ElevatorBtn[index];
  END_IF;
 END_IF;
 END_IF;END_FOR;
EDIT 2019/01/24 : Correct fix for first value
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
MinValueNonZero :=0;FORindex:=1TO4
 IFElevatorBtn[index] >0THEN
 IFMinValueNonZero>ElevatorBtn[index] THEN
   MinValueNonZero :=ElevatorBtn[index];
 END_IF;
 END_IF;END_FOR;
Genius
I solved it by using a whole bunch of IF statments but I will change that för this. Thanks!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I've really struggled to find a way to do this but I cant seem to get it to work.
I want to get the minimum value from X amount of INT variables but not if its 0.
Theese are the once Ive tryed (and countless variations with <> 0 and so on):
Lets say the values are Var1 = 3, Var 2 = 5, Var3 = 0 and Var4 = 10
NewVariable := MIN(Var1, Var2, Var3, Var4);
This gives me the value 0.
NewVariable := LIMIT(1,(MIN(Var1, Var2, Var3, Var4)),15);
This gives me the value 1.
The value i really want is 3, which is the lowest value that is NOT 0.
A little brute force but you could do something like this.
Define a variable for the minimum value
MinVal: int := 32000;
If you put the values in an array, then you could loop through it in a FOR loop.
Thanks, that almost worked. But I want the MinValue to be at 0 value until 1 or more of Val1-5 goes over 0, then i want MinValue to have that value...
Maybe I should start to look for a diffrent solution.
Iam making an elevator for school, and Ive added a second elevatorcar and I want the it to go down
to the lowest floor as soon as 1 of 5 variables becomes active. If the MinValue is 0 the elevator stops.
EDIT 2019/01/24 : Correct fix for first value
Genius
I solved it by using a whole bunch of IF statments but I will change that för this. Thanks!
Edited my code