Thanks Dimster. I didn't think about including stock prices. A lot of calculators has 2-digit and 4-digit options. That's something I may consider.
@Codeguy: Hey, you're young, you can wait, but I've got to figure out a faster way to add commas. It appears that string replacement is much faster than string concatenation. I'll have to fool with that a bit, but I wanted to get the working components down and tested before I get into optimization and capacity. That LEN() limit is a bummer, but there are ways to save parts in arrays and get around that.
By bombing out, did you mean it wouldn't remove the commas? It took so long, I had to presume it couldn't process that large of a string. Instead of debugging it, as it may be a size limitation and it's bleeping slow, I decided to try a string replacement with INSTR().
m& = 1048576 * 1.25 - 1
j& = j& + 1
IF j&
MOD 3 = 0 AND i&
< m&
- 2 THEN i&
= i&
+ 1:
MID$(stringmathb$
, i&
, 1) = "," PRINT stringmathb$
, LEN(stringmathb$
), "Press a key to remove commas...":
SLEEP
i&
= INSTR(seed&
+ 1, stringmathb$
, ",") MID$(b$
, j&
+ 1, i&
- seed&
+ 1) = MID$(stringmathb$
, seed&
+ 1, i&
- seed&
- 1) j& = j& + i& - seed& - 1
seed& = i&
stringmathb$
= RTRIM$(b$
) + MID$(stringmathb$
, seed&
+ 1): b$
= ""
That's bleeping fast! Thank you for your post, which lead me to surmise QB handles string replacement infinitely faster than string concatenation. That's probably the case for all languages.
OK, I put together a way to add commas, too. This routine will take the 1M+ digits Codeguy provided and add commas, prompt, and remove commas. It's very fast, now!
m& = 1048576
LINE INPUT "Press Enter to add commas..."; null$
' Add commas
i& = 0: j& = 0: seed& = 0
seed&
= LEN(stringmathb$
) MOD 3:
IF seed&
= 0 THEN seed&
= 3 m2&
= (LEN(stringmathb$
) - 1) \
3 MID$(c$
, j&
+ 1, seed&
+ 1) = MID$(stringmathb$
, i&
+ 1, seed&
) + "," i& = i& + seed&: j& = j& + seed& + 1: seed& = 3
c$ = ""
PRINT "Length of string =";
LEN(stringmathb$
) LINE INPUT "Press Enter to remove commas..."; null$
' Remove commas
i& = 0: j& = 0: seed& = 0
i&
= INSTR(seed&
+ 1, stringmathb$
, ",") MID$(b$
, j&
+ 1, i&
- seed&
+ 1) = MID$(stringmathb$
, seed&
+ 1, i&
- seed&
- 1) j& = j& + i& - seed& - 1
seed& = i&
stringmathb$
= RTRIM$(b$
) + MID$(stringmathb$
, seed&
+ 1): b$
= "" PRINT "Length of string =";
LEN(stringmathb$
)
Pete