I had to find out what was wrong with a piece I had been working on so I come up with this if anyone is interested.
function WL_TRACE_INIT(file$)
global WL_TRACE_FP as integer
c as integer
c=1
while ( c <= 32 and file open( c ) )
inc c
endwhile
if ( c <= 32 )
WL_TRACE_FP=c
else
exitfunction
endif
if ( file exist(file$) )
delete file file$
endif
open to write WL_TRACE_FP,file$
` write our header
write string WL_TRACE_FP,"Trace file created : "+get date$()+", "+get time$()
write string WL_TRACE_FP,"File handle used : "+str$(WL_TRACE_FP)
endfunction
function WL_TRACE_CLOSE()
write string WL_TRACE_FP,"EOF Trace file (safe program exit)"
close file WL_TRACE_FP
endfunction
function WL_TRACE_WRITE(t$)
write string WL_TRACE_FP,t$
endfunction
At the beginning of your program just call WL_TRACE_INIT(filename$). At the end of your code just add WL_TRACE_CLOSE(). If your program exits safely then the close function will write a final line of text to the file.
Using it just call WL_TRACE_WRITE(mystring$). You can make up your strings just like in a print statement.
WL_TRACE_WRITE("Object count : "+str$(count))
WL_TRACE_WRITE("Xpos, Ypos, Zpos = "+str$(xpos)+","+str$(ypos)+","+str$(zpos))
If your program crashes then the text file will only have in it where it has got up to.
So far this has helped me with two bugs over the last twenty four hours. Hope it comes in useful for someone.
Warning! May contain Nuts!