Issues about if elseif end if ilogic rules

Issues about if elseif end if ilogic rules

Anonymous
Not applicable
1,068 Views
4 Replies
Message 1 of 5

Issues about if elseif end if ilogic rules

Anonymous
Not applicable

I am trying to do some rules with many variables height which lead to different result. However, the coding does not run well. I wish want to know which parts of the codes go wrong.

IF Else.png

 

0 Likes
Accepted solutions (1)
1,069 Views
4 Replies
Replies (4)
Message 2 of 5

Sergio.D.Suárez
Mentor
Mentor

Hi, my recommendation would be that you first try to verify the equalities separately. I can't try any solution because I don't have your specific parameters. I would recommend that you try an equality and put a message box when it exists. Many times the type of units and the decimal tolerance means that there is no equality (imagine if you really have 10 mm and you place 10 in cm, or for example they are 9.9999 mm).
If the problem persists, try to define the parameter through the document, it is often safer to define the parameter in this way.

 

Dim oDoc As Document= ThisDoc.Document
Dim oParam As Parameter = oDoc.ComponentDefinition.Parameters("d0")

 I hope this helps solve your problem. Regards


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

0 Likes
Message 3 of 5

JelteDeJong
Mentor
Mentor
Accepted solution

Hi

your "IF"statements are clear voor a human but a computer will interpret not like you would expext. Your if statments have a couple of faults.

  • If you use a "OR" in a "If" statement then the computer will evaluate what is before and afther the "OR" and then evaluate the "OR" statement.
  • When a value is converted to an boolean then it is always "True" unless its 0 then its "False".
  • x <= y <= z is always "False". i cant explain why.

for exapmle the if statment:

if height = 170 or 210

will always be true because

step 1: if (height = 170) or (210)

step 2: if (False or True) or (True)

step 3: if (true)

as you see beacause the right boolean value is true (step 2) the if statement is always true.

i have simplified your code with this rules in mind and then i get:

If Height <= 168 Or Height = 228 Or Height = 258 Or  Height = 345 Or  Height = 365 Or  Height = 395 Then
	h0 = 12
	h1 = 12
Else
	h0 = 14
	h1 = 14 
End If

I would advice you to use a "select case" statment. your code would the look more like this:

Dim height = Height
Dim hValue = 0
Select Case Height
        Case 0 To 168
                hValue = 12
        Case 200 To 208
                hValue = 12
	Case 228
		hValue = 12
	Case 258
		hValue = 12
	Case 345
		hValue = 12
	Case 365
		hValue = 12
	Case 395
		hValue = 12
	Case 424 To 424
		hValue = 12
	' TODO add more cases for hValue = 12 .......
	
	Case 170
		hValue = 14
	Case 210
		hValue = 14
		
	Case 482
		hValue = 12
	Case 502
		hValue = 12
	' TODO add more cases for hValue = 12 .......
End Select
h0 = hValue
h1 = hValue

i hope that this code explains it self if it does not feel free to ask.

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 4 of 5

Anonymous
Not applicable

Thank you for the help, the situation i faced was exactly like u state above. Some of the value always getting false value.
Besides, if i have 2000+ combination which mean i need to have 2000+ cases right?

 

0 Likes
Message 5 of 5

JelteDeJong
Mentor
Mentor

if you have 2000+ combination then you will also need 2000+ cases. But it should be posible to get that number down. creating a rule with 2000+ case statements is not effecient. I would expect that there is a formula to calculate in wich catetgory the heights should fall. if you know what that formula is i would program that.

If that is not the case and it's realy not possible to do it with out "If" or "Select case" statements then maby you can optimase it. Maby it's possible to say "h0" and "h1" are always 12 except in 200 cases. then you set

Dim hValue = 12

(in my example) Then write only the exceptions in the  "Select case".

I dont know the exact situation but i expect that there are better solutions

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes