|
Post by milfredo on Jun 23, 2020 21:51:26 GMT -5
I have a ton of experience with RAC files, but virtually none with Sequential files. I went to the help file and my problem wasn't really addressed. I tried to use one of the examples, but here is the problem.
open "test.txt" for output as #1
print #1, "item three ";
print #1, "item four ";
Close #1 I cannot find the file after I close my program. I'm writing a CSV file to be saved and I have all the code written but the file doesn't show up. So I tried the example above and can't find it either.
ThanksMilfredo
|
|
cundo
Full Member
Muchas Gracias!!
Posts: 146
|
Post by cundo on Jun 23, 2020 22:04:18 GMT -5
Print the StartupDir$ and DefaultDir$ variables at the beginning of your code. Probably the file is at DefaultDir$. Alternatively you could just code a path to save to.
|
|
|
Post by milfredo on Jun 23, 2020 22:18:35 GMT -5
Thanks I will give that a try.
|
|
|
Post by milfredo on Jun 23, 2020 22:34:37 GMT -5
[CSVCode] Textdir$ = DefaultDir$ '*** CSV code open "test.txt" for output as #1 I have code in here... then at end of code have this
close #1
The default dir is C: but the file does not show up. Even if my code didn't produce anything in the file, a file should still be created, Right?
|
|
Tasp
Full Member
Posts: 215
|
Post by Tasp on Jun 24, 2020 0:39:30 GMT -5
You code works fine for me and places the test.txt file in the same directory that I had your code saved in.
However you mention you're using the C directory, so this maybe a permissions issue.
Are you running LB as Administrator? If not try that. Alternatively, try giving your file a its own path and folder outside the Root C drive.
[CSVCode] Textdir$ = DefaultDir$ + "\test.txt" Print Textdir$ '*** CSV code open Textdir$ for output as #1 NOTICE "File location " + Textdir$ close #1
|
|
|
Post by milfredo on Jun 24, 2020 1:39:00 GMT -5
Thank you for the help. I will try it.
|
|
|
Post by Rod on Jun 24, 2020 1:56:53 GMT -5
Also be sure your code is actually getting run. Put a simple print statement in the loop so you can see the records getting written in the mainwin.
|
|
|
Post by milfredo on Jun 24, 2020 15:58:23 GMT -5
Thanks Rod. I did. Things seem to be working right now, just having to work on the formatting.
|
|
|
Post by donnybowers on Jun 27, 2020 3:48:03 GMT -5
This code will cause your file "test.txt" to be written to the default directory, relative to where you have saved your program. If you were using LB for the first time after installation and you just wrote the program and didn't save it, your file "test.txt" would be written to the Liberty BASIC 4.x program directory. You should create a sub-folder (i.e. My Program or MyPrograms/ProgramName) somewhere in your USER folders (i.e. Documents) and save your program to that folder whenever you are writing a program. I can't see any way that this code wouldn't work. open "test.txt" for output as #1 print #1, "item three "; print #1, "item four "; Close #1
The following code will read your "test.txt" file and print it to the screen. open "test.txt" for input as #1 while eof(#1)=0 'loop until you reach the end of the file (eof) line input #1, item$ print item$ wend close #1
Unless something's seriously wrong with your computer or your Liberty Basic program has become corrupted somehow, I'm certain the file is there in whatever default directory you're working in.
There are no errors in your code. You could use a full path to whatever folder (directory) you want your file to be in like this: open "c:\MyPrograms\myfolder\test.txt" for output as #1 print #1, "item three "; print #1, "item four "; Close #1
But the way you wrote it the file will automatically be saved to whatever your default folder is, relative to whereever you have saved your program. You can also save it to a sub-folder under your default folder (default directory) like this. open "myfolder\test.txt" for output as #1 print #1, "item three "; print #1, "item four "; Close #1
This is called a relative path. Let's say you are currently working in a folder called "c:\MyPrograms". The full path to "test.txt" would then be "c:\MyPrograms\myfolder\test.txt" using the above version of the program. The relative path, if your program is saved in "c:\MyPrograms", is simply "myfolder\test.txt". The problem with a full path is that if you move your program to a different directory for whatever reason, you have to change the path name in your program or you'll encounter an error. One way around this is to use DefaultDir$ as follows: fullPath$=DefaultDir$+"\myfolder\test.txt" ' this will place "c:\MyPrograms\myfolder\test.txt" into the variable fullPath$ open fullPath$ for output as #1 ' open the file using the variable fullPath$ print #1, "item three "; print #1, "item four "; Close #1
One trick is to re-run your program with the following command added: print DefaultDir$
Temporarily placing this command in your file will print out the path name of exactly where your file is in your file system.
Note: Programmers usually call file folders "directories", which just an older term for file folders on a computer. When Microsoft made their first operating system DOS (Disk Operating System) they called them directories instead of folders. The term has pretty much stuck in the programming community.
I'm sure you may be aware of some of this info if not all of it, but I'm just trying to be helpful just in case.
|
|
|
Post by milfredo on Jun 27, 2020 22:31:37 GMT -5
Thank You very much.
|
|