Community
Inventor Forum
Welcome to Autodesk’s Inventor Forums. Share your knowledge, ask questions, and explore popular Inventor topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Simply iLogic code?

2 REPLIES 2
Reply
Message 1 of 3
Mack_1979
212 Views, 2 Replies

Simply iLogic code?

Hi everyone,

 

My code look something like this:

 

If a <= 100 then
d1 = d1 +1
elsif d1> = 150 then
d1 = d1-1
endif

 

I would like to have d1 within the interval 100;150. However, when d1 = 1, then the new d1 = d1 +1 = 2 and not 100.

Must be + or -1. 

 

Thank you in advance.

2 REPLIES 2
Message 2 of 3
bgarden
in reply to: Mack_1979

If d1<= 100 then
d1 = d1 +(100-d1)

 

Maybe?

Message 3 of 3
JavaLodge
in reply to: Mack_1979

It might help if you explain what you want to do with this code.  Right now, the code is doing exactly what you've told it to do.  It will check once whether a is between 100 and 150.  If it's too low, it adds 1 to d1.  If it's too high, it subtracts one.  It will only do this once because it's in an if statement.  So if d1 = 1, then the first part of the if statement is true, and it will add one to that.

 

Actually, on second look, did you mean to put a in line 1?  Just a guess, but shouldn't it read:

 

If d1 <= 100 then
d1 = d1 +1
elseif d1> = 150 then
d1 = d1-1
endif

 

If you want to always keep d1 between 100 and 150 then you could do this:

 

If d1 <= 100 then
d1 = 100
elsif d1> = 150 then
d1 = 150
endif

 

That way if the value of d1 drops below 100 then it will automatically be set at 100 and vice versa.

____________________________________________________________
Slow is good and good is fast.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report