Close TIME.DAT after opening it. If the variable arg to @DO .. IS, @DO .. ADD, and @IF ... IS is a string, do not expand bare numeric variables (like X and Y).