kees
New Member
Posts: 2
|
Post by kees on Nov 3, 2023 19:52:56 GMT
From the Tutorial I copied this:
open "numbers.txt" for output as #out for x = 1 to 10 print #out, x next x close #out
When I want to run this, the first line is highlighted and at the bottom is the message: Basic Compile Halted: Bad file handle: #
What is wrong here?
|
|
|
Post by tsh73 on Nov 4, 2023 5:54:00 GMT
It seems that out recognized as a keyword. Use another name, that's all.
|
|
kees
New Member
Posts: 2
|
Post by kees on Nov 11, 2023 18:45:56 GMT
Indeed, I see that in the meantime in the Tutorial "#out" has been changed into "#numbers". Now 'Run' does not stop at the filehandler, but I get the "Warning: Runtime Error: Attempted to kill non-existant file numbers.txt (see error.log for more information)." What is wrong this time now?
addendum: This happens in:
'open a file, and print some information into it, then close it open "numbers.txt" for output as #numbers for x = 1 to 10 print #numbers, x next x close #numbers
'open the original file for input open "numbers.txt" for input as #in 'open the new file for output open "numbers2.txt" for output as #numbers
[copyLoop] 'copy the contents of numbers.txt to numbers2.txt if eof(#in) then [doneCopying] 'we reached the end of the file input #in, value print #numbers, value goto [copyLoop]
[doneCopying] 'close numbers.txt & print new numbers into numbers2.txt close #in for x = 11 to 20 print #numbers, x next x close #numbers 'delete the original numbers.txt file kill "numbers.txt" 'rename numbers2.txt to numbers.txt name "numbers2.txt" as "numbers.txt"
end
|
|
|
Post by Rod on Nov 11, 2023 18:51:20 GMT
Well the error message is plain English. Either it does not exist or perhaps it had not been closed, and so does not exist.
What happens if you use the debugger and step through the program. Good to get used to the debugger. It will help you solve lots of coding bugs.
|
|
|
Post by tsh73 on Nov 11, 2023 19:18:19 GMT
1) to have kill error, you need KILL statement (not in code you posted, as of now) 2) first time, "numbers.txt" is not created yet so KILL would not find it 3) it happens that
kill "numbers.txt" does not work, You need to supply path to file There is a DefaultDir$ predefined variable, containing current folder So
kill DefaultDir$;"\";"numbers.txt" seems working.
kill DefaultDir$;"\";"numbers.txt" open "numbers.txt" for output as #numbers for x = 1 to 10 print #numbers, x next x close #numbers
(I have no idea where you put that KILL statement. If you do
open "numbers.txt" for output it will overwrite the file anyway, so KILL before open is kind of pointless. If you KILL file after writing you will not have file any more - again, pointless? So probably you should just remove KILL )
Also To open that file in Notepad, add this line after closing file:
run "notepad.exe ";DefaultDir$;"\";"numbers.txt"
|
|