This is wrong:

print(TO_LOG,"\n %d",dataStr(nHandle,j,0));

will produce wrong output because dataStr is a string, not a int.