Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Reading file
#1
I just downloaded qb64 and it seems marvelous! I had written several programs in QB4.5 and I would like to review and revise some of them. Last time I used QBasic was inside DOSBox, but did not like it very much.

Now, I try to run a program that reads the coastline coordinates of the continents and prints maps, but the qb64 exe file does not find the coordinates file, though it is in the same (GEOGRAFY\) directory:

OPEN "GEOGRAFY\PMAP1.PNT" FOR RANDOM AS #1 ...

What is the correct file address of PMAP1.PNT?
Reply
#2
Hi !By default, it saves to the same location as your QB64 executable. You can change this behavior to make it save wherever your source code is located by clicking "Run" and then selecting "Output EXE to Source Folder".
Reply
#3
If the folder "GEOGRAPHY" is inside QB64PE folder, try this:

OPEN ".\GEOGRAFY\PMAP1.PNT" FOR RANDOM AS #1
10 PRINT "Hola! Smile"
20 GOTO 10
Reply
#4
Another really easy and flexible option is now:

files$ = _OPENFILEDIALOG$("Open File", "", "*.PNT", "Map files", -1)
IF file$ = "" THEN END 'user hit cancel and didn't enter a pnt file.
OPEN file$ FOR RANDOM AS #1

Like this, you can navigate and choose which file you'd like to open and use, rather than just hardcoding the name and path into your program.
Reply
#5
@emfril Welcome!

MasterGy's tip addresses the #1 problem for old QB fans experiencing QB64 for first time, so i am repeating it. You must click the "Output EXE to source folder" so that there is a bullet next to that option whenever you click the Run menu in the IDE. This puts the compiled .exe program in the same folder as your .bas and that should be same folder as your project files for that .bas source.

Steve's idea is good too, with an extra line or 2, you can choose from a multitude of files to run in your program!
b = b + ...
Reply
#6
(02-13-2024, 02:22 PM)MasterGy Wrote: Hi !By default, it saves to the same location as your QB64 executable. You can change this behavior to make it save wherever your source code is located by clicking "Run" and then selecting "Output EXE to Source Folder".

Yes, I made this mistake initially but fount it out soon enough. It didn't correct the problem though...
Reply
#7
(02-13-2024, 02:32 PM)Ikerkaz Wrote: If the folder "GEOGRAPHY" is inside QB64PE folder, try this:

OPEN ".\GEOGRAFY\PMAP1.PNT" FOR RANDOM AS #1
No, the same result:

Line 446 (in main module)
Path not found

I wish there was a way to find out *where* it's looking for the file, then it would be easy to correct the mistake...

What should the path should be if I make a copy of the pnt file in the same folder as the bas and the created exe files?
Reply
#8
"./" if it's in the same directory as the BAS file and EXE.  (".\", depending on OS.)

You can always hard code the FULL PATH, as long as that file isn't going to move on you.  "C:\My Folder\My Subfolder\My File.txt"
Reply
#9
And _CWD = "Current Working Directory", QB64 has that built in and tracks for you. You can use it to check where you are in your folder system as your program is running.

And also you can use _FileExists(PathedFileName$) to check that the file (at the optional named path) does exist and you can open it without error.
b = b + ...
Reply
#10
(02-18-2024, 10:50 AM)bplus Wrote: And _CWD = "Current Working Directory", QB64 has that built in and tracks for you. You can use it to check where you are in your folder system as your program is running.

And also you can use _FileExists(PathedFileName$) to check that the file (at the optional named path) does exist and you can open it without error.
Thanks! This works:

      OPEN "C:\MYSTUF~1\MYFILE~1\QB\GEOGRAFY\PMAP1.PNT" FOR RANDOM AS #1 LEN = LEN(PNTData)

The source file and the executable file are in the folder:
    \GEOGRAFY\GEAMAP\

So want should have been the correct abbreviated form of the statement?

Also, in QB64 do I have to use MYSTUF~1 as in QBASIC and DOS (instead of MYSTUFF)?
Reply




Users browsing this thread: 2 Guest(s)