Ilogic Odd Number Pattern

Ilogic Odd Number Pattern

cjackson9613
Enthusiast Enthusiast
1,569 Views
3 Replies
Message 1 of 4

Ilogic Odd Number Pattern

cjackson9613
Enthusiast
Enthusiast

I'm sure there is an easy solution, but I'm still new to Ilogic.

I have 1 column pattern. The quantity of rows is determined by height / spacing. If the number is odd I need to subtract 1 row. I'm not sure how to tell it to read odd numbers.

 

Qty = round(Height/Spacing)

If Qty = Odd Then

   Qty - 1

End If

0 Likes
Accepted solutions (2)
1,570 Views
3 Replies
Replies (3)
Message 2 of 4

rikard.nilsson
Collaborator
Collaborator
Accepted solution

Hi,

 

Here is one way to solve it..

 

Dim testQty As Integer = 11

If testQty Mod 2 <> 0 Then
	testQty = testQty - 1
End If

MessageBox.Show(testQty, "Title")

 

Regards

Rikard 

0 Likes
Message 3 of 4

DRoam
Mentor
Mentor
Accepted solution

iLogic uses VB.net, so you can often find how to do things by googling "vb.net" followed by what you want to do, e.g. "vb.net if number is odd". Based on those results, it looks like using Mod is the way to go:

 

Qty = round(Height/Spacing)

If Qty Mod 2 <> 0 Then Qty -= 1

Basically, this works by checking the remainder of dividing Qty by 2. If the remainder of dividing a number by 2 is zero, the number is even. If the remainder is not zero, the number is odd (or a non-integer, but you've handled that with your Round statement).

 

Another tip, if your "If" statement has no "else" condition and only does one thing, you can compact it to a single line, as I did above.

 

One last thing, I used the shorthand "-=" to subtract one from the Qty variable. You can use += to add to a variable. Comes in handy pretty often.

Message 4 of 4

cjackson9613
Enthusiast
Enthusiast

Thank you. I appreciate the explanations, this really helps me understand why it's done this way. 

0 Likes