The main problem is you use the return key as your input for asking if they want to delete the file or not. When you use returnkey() it instantly works and any lines under it (like suspend for key) won't work because the return key is still being held down. This program goes so fast it reads the returnkey from the delete file question and as the user is finished with his inputing his name. Thus the name$ is nothing but a blank line. The file is actually deleted but remade (with a blank name) so fast it doesn't look like it's deleting the file.
When you use "input" it's best not to turn on syncing. Input freezes all actions till the user presses enter... meaning there's no place to add a sync to see the user input.
If you open and write a file there's no need to check for the file being open outside of the "if file exist()"... put "close file 1" inside the "if file exists()" statement because you know for a fact that inside that "if file exists()" statement the file is opened.
If you want programs to use the escape key always add "disable escapekey()" near the top of the program. Without that line pressing ESC will always escape out of a program even when you don't have lines like "if escapekey()=1 then end". I changed your question input to inkey$() so I changed them to a "Y" or "N" question.
I lined up all the loops. It's always good to space it out so you can see where each loop begins and ends... makes debuging and finding nested if errors a lot easier. Write code with spaces and you'll never regret it later.
Hope this helps:
do
cls
save$="save2.dat"
`if file do not exist you will make a file
if file exist(save$)=0
`put something in a file
input "What is your name? ";name$
`make a file
open to write 1,save$
`write the name to file
write string 1,name$
close file 1
endif
`open file to read
if file exist(save$)=1
open to read 1,save$
`read string
read string 1,name$
close file 1
set cursor 0,0
cls
`print the string
print "Name = "; name$
`delete or don't delete
text 100,100,"do you want to delete your name? (Y)es (N)o"
do
a$=inkey$()
a$=upper$(a$)
if a$="Y"
delete file "save2.dat"
text 100,200,"deleted"
` leave the loop
exit
endif
if a$="N"
end
endif
loop
endif
loop