Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

iLogic treating ElseIf statement as an Else statement

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
sam_pinches1
204 Views, 2 Replies

iLogic treating ElseIf statement as an Else statement

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. 
 

Tags (2)
2 REPLIES 2
Message 2 of 3
Stakin
in reply to: sam_pinches1

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
Message 3 of 3
sam_pinches1
in reply to: Stakin

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.

Post to forums  

Technology Administrators


Autodesk Design & Make Report