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

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

cheers, that's very helpful...
have a good one

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

Yeah that's true, but I got the idea...

if Z is interger, you also can do this way without using If

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

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?

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

and i got another one line solution

SIDE = IIf(Z Mod 2, W - (V / 3600#), W + (V / 3600#))

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.

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

Which of us are you talking to ??

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.