Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What's the best way to say "If x=1000,2000,3000,4000,5000" 1

Status
Not open for further replies.

GSMike

Programmer
Feb 7, 2001
143
US
I need to determine is "X" is a multiple of 1000.
I know I can say,

Code:
If x=1000 or x=2000 or x=3000 or x=4000 or x=5000 or x=6000....adinfinitum

but I'm thinking there must be a better way, like with the "In" operator in SQL or VB with strings:

Code:
If x in ("a","b","c", etc).

or is there an even better way, like with some kind of formula?

Thanks for your help.

Mike

 
in excel there is a function called Mod. This finds the remainder when the number is divided.

eg =Mod(4000/1000) this would return 0.

Not sure what this function is called in VB. but you can just divide X by 1000 then check if the result is an integer.

you would then just use an If statement.
 
The Mod function can be achieved by doning this:

Remain = x - (1000 * Int(x / 1000))

so your code would be:

If (X - (1000 * Int(X / 1000))) = 0 then "Do Stuff"
 
There is a mod, written as 100 mod 11. may be quicker, and easier on the eye than the remainder method (used to do that in assembler!) Peter Meachem
peter@accuflight.com
 
if divisibility by 1000 is what u're looking for u can simply use the condition:
if(right(x,3)="000",val1,val2)
This is a beautiful feature Excel has - of coercing a number to a string and vice versa depending upon the usage context - try it out.
 
If do it in VB or VBA, you can simply use MOD function as:
If X Mod 1000 = 0 then
dosth
end if


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top