| | |
If functions
Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Sep 2005
Posts: 16
Reputation:
Solved Threads: 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
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
•
•
Join Date: Jun 2005
Posts: 70
Reputation:
Solved Threads: 2
Sorry purplegerbil, but that makes all 6 values equal the same thing.
Try this:
Try this:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
If Z = 1 Or If Z = 3 Or If Z = 5 Then<blockquote>SIDE = W - (V/3600#)</blockquote>End if If Z = 2 Or If Z = 4 Or If Z = 6 Then<blockquote>SIDE = W + (V/3600#)</blockquote>End If
if Z is interger, you also can do this way without using If
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
SIDE = W + ((-1) ^ Z)*(V / 3600#)
first i check grandfilth code pattern
then we got
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
then we got
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
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
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
SIDE = IIf(Z Mod 2, W - (V / 3600#), W + (V / 3600#))
![]() |
Similar Threads
- VB's Left, Right, Mid Functions in C++? (C++)
- User defined functions (C++)
- Double Linked Lists and Functions required (C++)
- How to write FNVAL functions (Java)
- I dont see any difference between these 2 functions, DO YOU? (C)
- access Digital Camera Functions (C++)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: hi
- Next Thread: Brand new to VB
| Thread Tools | Search this Thread |
* 6 429 2007 access activex add age append application basic beginner birth bmp calculator cd cells.find click client code college column component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report retrieve save search sendbyte sites sort sql sql2008 sqlserver subroutine table tags textbox time timer urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows





