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: 

If... Otherwise...

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
BeKirra
357 Views, 6 Replies

If... Otherwise...

Suppose there are 2 "if" statements.

I'd like to add something else if they are not the case.

Here is what I have but it doesn't work.

Thanks in advance.

 

Edit:

I am not familiar with iLogic.

The code below is not actual code but logical thinking.

Your help will be much appreciated.

 

 

Select Case 1 And 2

Case 1
"if" statement 1
(e.g. if it is an apple, do something)
Case 2
"if" statement 2
(e.g. if it is a pear, do something)
Case Else
Do something else

End Select

 

 

Please mark "Accept as Solution" and "Like" if my reply resolves the issue and it will help when others need helps.
= ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ =
A circle is the locus of a cursor, starting and ending at the same point on a plane in model space or in layout such that its distance from a given coordinates (X,Y) is always constant.
X² + Y² = C²
6 REPLIES 6
Message 2 of 7
Michael.Navara
in reply to: BeKirra

If you want to test one variable to multiple values, you can use Select-Case statement

 

Dim myValue = 1 'Set your current value
Select Case myValue
    Case 1
        Logger.Debug("Value is ONE")
    Case 2
        Logger.Debug("Value is TWO")
    Case Else
        Logger.Debug("Value is something different")
End Select

 

 

If you want to test more than one variable, you need to use If-ElseIf-Else statement 

 

Dim myValue1 = 1
Dim myValue2 = 2
If myValue1 = 1 Then
    Logger.Debug("myValue1 is ONE, myValue2 is anything")
ElseIf myValue2 = 2 Then
    Logger.Debug("myValue1 is NOT ONE, myValue2 is TWO")
Else
    Logger.Debug("myValue1 is NOT ONE, myValue2 is NOT TWO")
End If

 

 

Or you can use nested If statements

 

Dim myValue1 = 1
Dim myValue2 = 2
If myValue1 = 1 Then

    If myValue2 = 1 Then
        Logger.Debug("myValue1 is ONE, myValue2 is ONE")
    ElseIf myValue2 = 2 Then
        Logger.Debug("myValue1 is ONE, myValue2 is TWO")
    Else
        Logger.Debug("myValue1 is ONE, myValue2 is NOT ONE or TWO")
    End If

ElseIf myValue1 = 2 Then

    If myValue2 = 1 Then
        Logger.Debug("myValue1 is TWO, myValue2 is ONE")
    ElseIf myValue2 = 2 Then
        Logger.Debug("myValue1 is TWO, myValue2 is TWO")
    Else
        Logger.Debug("myValue1 is TWO, myValue2 is NOT ONE or TWO")
    End If

Else
    Logger.Debug("myValue1 is NOT ONE or TWO, myValue2 is anything")
End If

 

 

It depends on what do you want to test.

 

 

Message 3 of 7
BeKirra
in reply to: Michael.Navara

Thanks.

 

Here is what I wrote after reading your code.

Will it work?

 

 

Dim Letter As String
Dim Person As String
Dim Greeting As String
Dim Meeting As String

Select Case Letter

Case 1
If Person = "A"
Greeting = "Hello"
End If

Case 2
If Person = "B"
Greeting = "Hi"
End If

Case Else
Meeting = "Good Morning"

End Select

 

 

Please mark "Accept as Solution" and "Like" if my reply resolves the issue and it will help when others need helps.
= ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ =
A circle is the locus of a cursor, starting and ending at the same point on a plane in model space or in layout such that its distance from a given coordinates (X,Y) is always constant.
X² + Y² = C²
Message 4 of 7
Michael.Navara
in reply to: BeKirra

Syntax of your code is almost correct, but I don't understand what do you try to do.

Can you describe your use case? What is your inputs, conditions and expected result?

 

Note: You can't compare value of variable Letter (String) with expected value 1, 2 (Integer)

Message 5 of 7
Curtis_Waguespack
in reply to: BeKirra

@BeKirra, see if these example help clarify things.

 

Dim Letter As String
Dim Greeting As String
Dim LetterList = New String(){"A", "B", "Z"}

Letter = InputListBox("Prompt", LetterList, "A" , Title := "Letter List", ListName := "List")

Select Case Letter
	Case "A"
		Greeting = "Hello"
	Case "B"
		Greeting = "Hi"
	Case Else
		Greeting = "Good Morning"
End Select

MsgBox(Greeting,,"iLogic")

 

Same but using an If statement rather than a Select Case statement. 

Dim Letter As String
Dim Greeting As String
Dim LetterList = New String() {"A", "B", "Z" }

Letter = InputListBox("Prompt", LetterList, "A", Title := "Letter List", ListName := "List")

If Letter = "A" Then
	Greeting = "Hello"
ElseIf Letter = "B" Then
	Greeting = "Hi"
Else
	Greeting = "Good Morning"
End If

MsgBox(Greeting, , "iLogic")

 

 

Message 6 of 7
Frederick_Law
in reply to: BeKirra

Message 7 of 7
BeKirra
in reply to: BeKirra

Thanks to ALL.

I have figured out the logical statements based on what you suggested as my case is more complicate.

Please mark "Accept as Solution" and "Like" if my reply resolves the issue and it will help when others need helps.
= ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ =
A circle is the locus of a cursor, starting and ending at the same point on a plane in model space or in layout such that its distance from a given coordinates (X,Y) is always constant.
X² + Y² = C²

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

Post to forums  

Autodesk Design & Make Report