For what you're doing in the loop you've presented, you're not actually putting 10,000-digit numbers into a string. You're simply using a string to extract parts of a number stored in a regular numeric variable. You are doing two main operations: [tt]
VAL(
RIGHT$(temp$, 1))[/tt], which gives the units place digit, and [tt]
VAL(
LEFT$(temp$,
LEN(temp$) - 1))[/tt], which gives the remaining digits.
Since the number stored in [tt]temp$[/tt] comes from the existing variable [tt]tempo[/tt], you can use the following numeric operations to achieve the same result much more quickly:
[ol]
[li]To retrieve the units place digit, use [tt]tempo
MOD 10[/tt]. To understand why this works, you need of course to understand what the [tt]
MOD[/tt] operator really is. Remember back to your elementary school days, when they taught you long division. When you finished dividing the integer part of the number, you stopped division and simply wrote the remainder next to the quotion. For example, 10 / 3 would come out 3R1, meaning a remainder of 1. The [tt]
MOD[/tt] operator performs this integer division and returns the remainder instead of the quotient.[/li]
[li]To discard the units place and shift everything to the right, use [tt]tempo \ 10[/tt]. The [tt]\[/tt] operator is very similar to the [tt]/[/tt] operator, except that it, like the [tt]
MOD[/tt] operator, performs an integer division. The [tt]\[/tt] operator is the partner to the [tt]
MOD[/tt] operator, in that it returns the quotient that [tt]
MOD[/tt] discards. If you divide 10 by 3 using the [tt]/[/tt] operator, you get 3.33333, but using the [tt]\[/tt] operator, you get only 3. Since the decimals go entirely into the remainder, which is returned by [tt]
MOD[/tt] and discarded by [tt]\[/tt], you do not need to worry about the remainder being greater than half of the divider (which would traditionally cause the response to be rounded up). In other words, 5 \ 3 = 1.[/li]
[/ol]
So, you can rewrite your loop more efficiently as follows:
[tt]
FOR r = nomchi
TO 1
STEP -1
tempo = (suite(r) * expo) + reste
suitetotal(r) = tempo
MOD 10
reste = tempo \ 10
NEXT r
[/tt]
You should find that this offers a drastic improvement in speed
