Ah, I misinterpreted you original post. You're looking to determine all factors for a number. Well I'm sure there is a more elegant way to do it, but here's one method:
Demo
Capx
I use a method called trial factoring. Basically, you take the starting number, take its square route and round it up to the nearest integer(i.e. whole number). Let's call that number "i". Now, try dividing the original number by every integer between 0 and i. For every division resulting in an integer, both "i" and the result are factors. Here's an example:
Starting number = 22
The square route of 22 rounded up = 5
22/1 = 22, so 1 and 22 are factors
22/2 = 11, so 2 and 11 are factors
22/3 = not an integer, so no factors
22/4 = not an integer, so no factors
22/5 = not an integer, so no factors
I hope this helps.
EDIT - Updated capx to use a much less convoluted method for testing for integers, incorporated an array to make sorting easier, and annotated everything. AnD4D