|
Post by click22 on Jun 17, 2022 16:32:12 GMT
Some 10 years ago I wrote a shopping list program in JB, and my wife has been using it ever since. I thought I would try to convert it to JB2, but now in my eighties I fell at the first fence. I have a sequential file containing all the data (item name, aisle, price etc) but I cannot access it with my existing code:
open "d:\testfile.txt" for input as #1 (A one line program pointing at a sequential file on a USB stick, to avoid confusion over folders)
But I get the JB message: 'Run Time Error: OS Error: The system cannot find the file specified.'
I have literally spent hours experimenting, but cannot resolve the issue that has worked for a long time under JB1. Any suggestions would be gratefully received. I suspect the answer will be obvious!
Brian
|
|
|
Post by tsh73 on Jun 17, 2022 16:45:18 GMT
See if Windows hides extension, and your file is actually named "d:\testfile.txt.txt"
Try to create file from JB and see how it get named
Somehow this code works for me on disk E: but not on D: (really surprised, obviously some rights issue)
open "d:\test01.txt" for output as #1 print #1, "Hello there" close #1
input "Press ENTER to read file back"; dummy$
open "d:\test01.txt" for input as #1 line input #1, a$ print a$ close #1
|
|
|
Post by click22 on Jun 17, 2022 17:07:30 GMT
Thanks for your suggestions tsh73. Sadly, the problem does not appear to be the file suffix. I also tried it with the file in the root of drive c (c:\testfile.txt) without success.
|
|
|
Post by plus on Jun 17, 2022 17:12:22 GMT
Yeah, are you sure you have the correct drive?
Can you find the file you want to open in Windows File Explorer? If so, are you matched with the pathed Filename?
|
|
|
Post by tsh73 on Jun 17, 2022 20:13:53 GMT
click22,
but did you run my code? Did it throw an error? Did it created a file? Did it read it back?
|
|
|
Post by plus on Jun 17, 2022 20:36:37 GMT
Hey tsh73 for the record it worked for me no error. I did not even know I had a disk D! ;-))
|
|
|
Post by Rod on Jun 18, 2022 7:09:40 GMT
When you run tsh73s code copy it directly from the forum. Don’t type it in. Highlight it in the forum page, press Ctr+C then start a new basic file in the JB editor and press Ctr+V to paste the code. Now run it and report your results.
You should also be able to use Windows Explorer, the folder icon, to see what drives you have and what USB stick is inserted and what Windows has named the USB stick. IT may not always be called D: Windows can assign another letter if you unplug and reinsert.
I have added directory info to tsh73's code it will give us a little more info.
print "DefaultDir is :";DefaultDir$ print "StartupDir is:";StartupDir$ print "Known drives are:";Drives$ open "test01.txt" for output as #1 print #1, "Hello there" close #1
input "Press ENTER to read file back"; dummy$
open "test01.txt" for input as #1 line input #1, a$ print a$ close #1
|
|
|
Post by click22 on Jun 18, 2022 17:43:11 GMT
print "DefaultDir is :";DefaultDir$
print "StartupDir is:";StartupDir$
print "Known drives are:";Drives$
open "test01.txt" for output as #1
print #1, "Hello there"
close #1
input "Press ENTER to read file back"; dummy$
open "test01.txt" for input as #1
line input #1, a$
print a$
close #1
Produces:
DefaultDir is :C:\Users\brian\AppData\Roaming\Just BASIC v2.0
StartupDir is:C:\Program Files (x86)\Just BASIC v2.0\
Known drives are:c: d: e: f:
Press ENTER to read file back
Hello there
|
|
|
Post by Rod on Jun 18, 2022 18:30:07 GMT
Ok, that worked using your C: drive. Using tsh73's code in the same way does it write the file to your USB stick on D:?
|
|