Hi,
I am pretty new to iLogic and VBA. I am attempting to change some physical parameters based on the value of another physical parameter. i.e. Change the value of PLATE_WIDTH and THK, based on the value of PLUG_OD. My code is as follows:
If PLUG_OD<100 Then PLATE_WIDTH = 40 THK = 16 ElseIf 100 <= PLUG_OD <300 Then PLATE_WIDTH = 60 THK = 20 ElseIf 300 <= PLUG_OD <500 Then PLATE_WIDTH = 80 THK = 25 ElseIf PLUG_OD>500 Then PLATE_WIDTH = 100 THK = 25 End If
The issue I am having is my outputs look like this:
if PLUG_OD<100 then PLATE_WIDTH = 40, THK = 16 (all good so far),
if 100 <= PLUG_OD <300 then PLATE_WIDTH = 60, THK = 20 (still all good)
if 300 <= PLUG_OD <500 then PLATE_WIDTH = 60, THK = 20 (wrong output)
if PLUG_OD>500 then PLATE_WIDTH = 60, THK = 20 (wrong output)
It is as if the first "IF" statement is considered, then the second statement is only considered as an "ELSE", ignoring all later "ELSEIF" statements. This holds true for if I comment out the first "ElseIF" statement, it is as if the code only considered the next ElseIF statement in line, and ignores the rest.
I have tried to replicated with other models / parameters and run into the same issue. BUT, I cannot see where I am going wrong according to the VBA documentation.
Solved! Go to Solution.
Solved by Stakin. Go to Solution.
change a bit
If PLUG_OD<100 Then
PLATE_WIDTH = 40
THK = 16
ElseIf PLUG_OD <300 and PLUG_OD <= 100 Then
PLATE_WIDTH = 60
THK = 20
ElseIf PLUG_OD <500 and PLUG_OD <= 300 Then
PLATE_WIDTH = 80
THK = 25
ElseIf PLUG_OD>500 Then
PLATE_WIDTH = 100
THK = 25
End If
Thanks! Some of the < and > were the wrong way around in your code but the principal worked!
Thanks very much.
Can't find what you're looking for? Ask the community or share your knowledge.