0

HI, sorry if this is really thick, but I'm abit stuck...I have written this piece of code as part of a bigger function:

If Z = 1 Then
SIDE = W - (V / 3600#)
End If
If Z = 2 Then
SIDE = W + (V / 3600#)
End If
If Z = 3 Then
SIDE = W - (V / 3600#)
End If
If Z = 4 Then
SIDE = W + (V / 3600#)
End If
If Z = 5 Then
SIDE = W - (V / 3600#)
End If
If Z = 6 Then
SIDE = W + (V / 3600#)
End If

I know it's a stupid way of doing it, but I tried:
If Z = 1 or 3 or 5 Then
SIDE = W - (V / 3600#)
else
SIDE=W + (V / 3600#)
End If

Could someone please help me to find a neater way of telling it to perform different formula for odd and even numbers?

Any help would be much appreciated

5
Contributors
11
Replies
12
Views
11 Years
Discussion Span
Last Post by w00dy
0

Sorry purplegerbil, but that makes all 6 values equal the same thing.
Try this:

If Z = 1 Or If Z = 3 Or If Z = 5 Then
[INDENT]SIDE = W - (V/3600#)[/INDENT]
End if
If Z = 2 Or If Z = 4 Or If Z = 6 Then
[INDENT]SIDE = W + (V/3600#)[/INDENT]
End If
0

I just realised it should have been

If Z = 1 Or Z = 3 Or Z= 5 (only one If at the start of the line, sorry, silly mistake)

However, Invisal, I like neat one-liners but I don't actually follow that one, could you explain it?

0

first i check grandfilth code pattern
then we got

If Z = 1 Or Z = 3 Or Z= 5 Then
     SIDE = W - (V / 3600#)
Else
     SIDE = W + (V / 3600#)
End If

mean if Z = odd number then SIDE = W - (V / 3600#)
and if Z = not odd number then SIDE = W + (V / 3600#)

my solution is SIDE = W + ((-1) ^ Z) * (V / 3600#)

if Z = odd number like 1, 3, 5 and etc..., then (-1)^Z = -1
if Z <> odd number like 2, 4, 6 and etc..., then (-1)^Z = 1


I am not good on explain so i hope you understan

0

Interesting, that. I'll do a test project and play with it, and the Iif one.
Have to say though that although I've used Iif before, I found that it didn't cope with complicated logic very well, so I stopped using it even though it meant a few more lines.

0

hey man ur coding isnt working ..........plz work on it

Which of us are you talking to ??

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.