|
-
Jan 5th, 2001, 12:43 AM
#1
Thread Starter
Frenzied Member
How would I write "If x cannot be evenly divided by 3, and x is not 0 then..."
I know how to write if x cannot be divided evenly by 3
[code]
If x Mod 3 = 0 Then
x = x + 1
End If
[code]
but how would i write the and x is not equal to 0?
-
Jan 5th, 2001, 12:45 AM
#2
Addicted Member
Code:
If x Mod 3 = 0 And Not x = 0 Then
-
Jan 5th, 2001, 02:58 AM
#3
Fanatic Member
-
Jan 5th, 2001, 05:41 AM
#4
Fanatic Member
OOPS Basic misunderstasnding here...
I know how to write if x cannot be divided evenly by 3
Code:
If x Mod 3 = 0 Then
x = x + 1
End If
x Mod 3 = 0 if AND ONLY if x CAN be divided equally by 3 (i.e. x = 3, 6, -3, 0)
Note that if x = 0 then x Mod 3 = 0
SO:
If x Mod 3 <> 0 Then x cannot be divided equally by 3 AND x cannot be 0.
So just use
Code:
If x Mod 3 <> 0 Then...
Cheers,
P.
Not nearly so tired now...
Haven't been around much so be gentle...
-
Jan 5th, 2001, 06:44 AM
#5
Registered User
Final Answer:
Final piece of code:
Code:
Dim X
If (X Mod 3)<>0 And X<>0 Then
'
'
End If
-
Jan 5th, 2001, 08:41 AM
#6
can som1 explain to me what MOD is/does? i looked it up and i can see how it works but i cant see how you peeps code will work
at the moment for things like this i would use
If (x / 3) = Int(x / 3) And x <> 0 then
End If
-
Jan 5th, 2001, 09:23 AM
#7
Fanatic Member
To re-iterate. 0 Mod n = 0 for any value of n
THEREFORE: If X Mod 3 <> 0 Then X CANNOT BE ZERO! That means that the 'And X <> 0' is redundant.
chenko: Mod is an operator that returns the remainder once the value has been divided by the divisor. So X Mod n will divide X by n and return the value of any remainder, thus 0 < X Mod n < n-1
0 Mod 3 = 0
1 Mod 3 = 1
2 Mod 3 = 2
3 Mod 3 = 0
4 Mod 3 = 1
5 Mod 3 = 2
6 Mod 3 = 0
7 Mod 3 = 1
8 Mod 3 = 2
etc.
OK?
P.
Not nearly so tired now...
Haven't been around much so be gentle...
-
Jan 5th, 2001, 09:48 AM
#8
Frenzied Member
base conversion
FYI:
You can use the mod operator for base conversion from a
higher base to a lower base. Like paul showed you, mod3
always returns 0,1,2 the digits of base 3. Base2 conversions
are useful:
Mod 2 always returns 0 and 1 so to convert 9 to base2:
9 Mod 2 = 1 - this is the first digit from right to left.
then 9 / 2 = 4
then 4 Mod 2 = 0 - next digit R -> L
then 4 / 2 = 2
then 2 Mod 2 = 0 - next digit
then 2 / 2 = 1
then 1 Mod 2 = 1 - next digit
then 1 / 2 = 0
STOP
so your binary number is: 1001
to check: 1*2^0 + 0*2^1 + 0*2^2 + 1*2^3 = 9
I can send you the code for a base10 to base2 converter if
you are interested.
-
Jan 5th, 2001, 09:50 AM
#9
Fanatic Member
Not nearly so tired now...
Haven't been around much so be gentle...
-
Jan 5th, 2001, 09:53 AM
#10
oh the remainder... i looked and got confused with th other part...thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|