Sam,
You are right. We should certainly get that change documented, and also change the examples shown under Open File.
There are a few ways to deal with paths through MapBasic. It depends on what you are saving, or where.
Here are a few ways to get to paths in MapBasic to avoid hardcoding them (which really should be avoided):
ApplicationDirectory$()
: Return the path/folder where your applications resided
PathToDirectory$(sFile)
: Return the path/folder from a given file
TempFileName$("")
: Returns a temporary file name in a given path/folder. "" will use the System Temp folder.
-
GetFolderPath$( folder_id
)
: returns the path to various locations on your system, like My Docs, My Pics, App Data, and MapInfo Preference folder.
These are just a few ways to get to folders.
For a temporary folder, I often do this:
sTempFolder = PathToDirectory$(TempFileName$(""))
I can now add the variable sTempFolder
to all my temporary file names:
Open File sTempFolder & "test.txt" For Output As #123
You can also use FileSaveAsDlg()
and FileOpenDlg()
to ask the user where to save or open data.
And finally, you can read a path from a configuration file.
------------------------------
Peter Horsbøll Møller
Principal Presales Consultant | Distinguished Engineer
Precisely | Trust in Data
------------------------------
Original Message:
Sent: 03-29-2023 19:51
From: Sam Wetsel
Subject: MapBasic Open File command no longer working
Yes, your answer gave me direction and I appreciate it, but I still have questions about absolute path and how I would do that.
After searching the Precisely knowledge base and not finding this addressed anywhere, I decided it was better to post this question in this forum so that Precisely employees could see it. I find it concerning that Precisely has modified a significant function in the way MapBasic works with regards to any file interaction requiring input or output functions without notifying users of this change. This makes all of my MB programs no longer backwards compatible in MI 2021 if they use input or output (or in other functions that I am not aware of that have been affected). There is nothing in the manual under the the Open File statement to this effect; in fact, it appears to be the same language it has been forever (see below). I have tried the Set Path command, but that doesn't work. I can't just hard code a path in every Open File command as my programs is used in different environments with different directory structures, so I don't know how to modify my programs to work correctly.
I'm sorry, I didn't mean to offend you by posting here. I just had a time restriction on getting this fixed.
------------------------------
Sam Wetsel
Anterix Inc
Woodland Park NJ
Original Message:
Sent: 03-29-2023 01:44
From: Uffe Kousgaard
Subject: MapBasic Open File command no longer working
I have already answered that question on MI-L. Wasn't the answer good enough?
------------------------------
Uffe Kousgaard
ROUTEWARE
Roskilde
Original Message:
Sent: 03-28-2023 13:05
From: Sam Wetsel
Subject: MapBasic Open File command no longer working
Hi all,
I recently upgraded to v2021.1 from v2019. I have a MapBasic program I wrote last year that worked fine, but now MI keeps on choking on the Open File command in the program. Has something changed with MapBasic language that there has been a change in how it handles the Open File command? I have looked in the reference book and everything looks the same. Someone mentioned that with MI v2021 there was a change so that you have to specify an absolute path.
Here is the code (stripped down to the relevant commands):
include "mapbasic.def"
Print "Writing test file"
Open file "test.txt" for output as #1
Print #1, "Hi"
Close File #1
This worked fine in MI v2019 and I have made no changes to the program code. I now get a error that it Cannot Open File "test.txt".
------------------------------
Sam Wetsel
Anterix Inc
Woodland Park NJ
------------------------------