At the point your script is failing there is no value in the variables varMinDate or varMaxDate.
I would recommend putting an Exit Script after the PEEK statements and view what is in the STCDAILY table. My guess is on the last row there is either an empty field, or a value that can not be translated as a number. It is also possible that STCDAILY doesn't have any rows in it.
You don't show the code where STCDAILY is loaded, so it is not clear whether that needs a change. It may be a WHERE statement needs to be added, or you need to check where it is loading from.