There is actually no need for the outer loop (for ndigits =1 to 19).
The matrix ib contains all the information. ib(x,1) contains all the 1 digit numbers, ib(x,2) all the two digit numbers..
ib(x,9) all the nine digit numbers. So to get up to 5 digits add ib(x,1)+ib(x,2)+ib(x,3),ib(x,4)+ib(x,5).
When I say 5 digit I mean 10000-99999.
So it might be even quicker! May even beat the C++, but as qb64 is converted to C before compiling this is not surprising.