08-20-2022, 09:52 AM
Here's a way which seems like it'd be mighty speed to me -- and it doesn't take any multiplication after a 1 run look-up table!
Make an array from 0 to 9. (DIM foo(9) AS STRING)
Take your divisor and multiply it by 0 to 9. Store the results.
For example, my divisor is 100.
foo(1) = 100
foo(2) = 200
...
foo(9) = 900)
With your lookup table, you now just grab chunks of your string and compare.
Write a SELECT CASE to find your value
SELECT CASE num2check$
CASE < foo(1): dividend = 0
CASE < foo(2): dividend = 1
CASE < foo(3): dividend = 2
....
CASE ELSE: dividend = 9
END SELECT
*******
In practice, let's use 123456789/ 3 as an easy example:
f1 = 3
f2 = 6
f3 = 9
... you get the array....
start with the first digit: 1... smaller than f1, result is 0. 1 - 0 = 1 carryover
bring down the 2. Value is now 12. is smaller than f5, result is 4. 12 - 12 = 0 carryover
bring down the 3. Carryover was 0, value is 3. Less than f2, result is 1. 3 - 3 = 0
bring down the 4. Carryover was 0, value is 4. Less than f2, result is 1. 4 - 3 = 1 carryover
bring down the 5. Carryover was 1, value is 15. Less than f6, result is 5....
... and on.
Instead of doing that multiplication math over and over, do it once and store it in an array. I imagine you'll save a boatload of time processing, if you do so.
Make an array from 0 to 9. (DIM foo(9) AS STRING)
Take your divisor and multiply it by 0 to 9. Store the results.
For example, my divisor is 100.
foo(1) = 100
foo(2) = 200
...
foo(9) = 900)
With your lookup table, you now just grab chunks of your string and compare.
Write a SELECT CASE to find your value
SELECT CASE num2check$
CASE < foo(1): dividend = 0
CASE < foo(2): dividend = 1
CASE < foo(3): dividend = 2
....
CASE ELSE: dividend = 9
END SELECT
*******
In practice, let's use 123456789/ 3 as an easy example:
f1 = 3
f2 = 6
f3 = 9
... you get the array....
start with the first digit: 1... smaller than f1, result is 0. 1 - 0 = 1 carryover
bring down the 2. Value is now 12. is smaller than f5, result is 4. 12 - 12 = 0 carryover
bring down the 3. Carryover was 0, value is 3. Less than f2, result is 1. 3 - 3 = 0
bring down the 4. Carryover was 0, value is 4. Less than f2, result is 1. 4 - 3 = 1 carryover
bring down the 5. Carryover was 1, value is 15. Less than f6, result is 5....
... and on.
Instead of doing that multiplication math over and over, do it once and store it in an array. I imagine you'll save a boatload of time processing, if you do so.