Hi Ryan
I can see where you come from but unfortunately, that's not how it works. The Readonly keyword only works one way: It makes a table read-only. Omitting the keyword doesn't mean that the table will be writable.
I use this structure to achieve what you are after:
sTempPath = PathToDirectory$(TempFileName$(""))
sSavePath = Left$(ImportPath, Len(ImportPath) - 4) + ".TAB
Register Table ImportPath
Type ASCII
Delimiter 44
Charset "WindowsLatin1"
into sTempPath
Open Table sTempPath
Commit Table PathToTableName$(sTempPath) As sSavePath
Close Table PathToTableName$(sTempPath)
Open Table sSavePath
If you do it often, convert it into a function:
Function OpenASCIIAsNativeTAB(ByVal ImportPath As String, ByVal bTitles As Logical, ByVal nDelimChar As Integer, ByVal sCharSet As String) As String
Dim sSavePath, sTempPath As String
OpenASCIIAsNativeTAB = ""
sTempPath = PathToDirectory$(TempFileName$(""))
sSavePath = Left$(ImportPath, Len(ImportPath) - 4) + ".TAB
If bTitles Then
Register Table ImportPath
Type ASCII
Delimiter nDelimChar
Titles
Charset sCharSet
into sTempPath
Else
Register Table ImportPath
Type ASCII
Delimiter nDelimChar
Charset sCharSet
into sTempPath
End If
Open Table sTempPath
Commit Table PathToTableName$(sTempPath) As sSavePath
Close Table PathToTableName$(sTempPath)
Open Table sSavePath
OpenASCIIAsNativeTAB = sSavePath
End Function
------------------------------
Peter Horsbøll Møller
Principal Presales Consultant | Distinguished Engineer
Precisely | Trust in Data
------------------------------
Original Message:
Sent: 01-22-2025 09:28
From: Ryan Cook
Subject: Opening a CSV with MapBasic
Yeah, I get that. But seeing as both open and register statements contain a read only parameter, it would be nice if that actually did something. I'm not sure what the point is of having a table referring to a CSV AND a copy of it for editing. If I want to register/open it as editable, MapInfo should be embedding that table in the native format, not keeping it read only and insisting I make another copy.
Interesting about the OGR Vectors. Will investigate that some more!
Thanks
R
------------------------------
Ryan Cook
ORH LTD
Original Message:
Sent: 01-22-2025 02:25
From: Peter Møller
Subject: Opening a CSV with MapBasic
Hi Ryan
As Steve wrote, a CSV file is read-only in MapInfo Pro.
The Reigster Table
statement creates a TAB that refers to the CSV file. The TAB file holds information about how to read the CSV file. That's why the table is read-only when you open it in MapInfo Pro.
To make it editable, save a copy of the YAB referencing the CSV into a Native/NativeX file.
The other benefit is that performance improves with a Native/NativeX TAB file compared to a CSV; Especially, a CSV with many records.
Alternatively, you can open the CSV using OGR Vector files. This comes with some benefits. MapInfo Pro can automatically detect the separator. MapInfo Pro can detect columns with X and Y coordinates and create points when opening the file. MapInfo Pro can detect columns with WKT (Well Known Text) and convert these to spatial objects when opening the file. MapInfo Pro can write edits back to the CSV file, ie. the file is no longer read-only.
OGR Vector Files has been supported since MapInfo Pro v2021.
Read more in this article MapInfo Monday: Improved way to opening CSV Files in MapInfo Pro v2021
------------------------------
Peter Horsbøll Møller
Principal Presales Consultant | Distinguished Engineer
Precisely | Trust in Data
Original Message:
Sent: 01-21-2025 05:06
From: Ryan Cook
Subject: Opening a CSV with MapBasic
I really don't understand why every time I use code to open a CSV, the table opens as read only.
Register Table ImportPath Type ASCII Delimiter 44 Charset "WindowsLatin1" into SavePath
Open Table SavePath
Why if BOTH register and open commands in MAPBASIC provide Read Only clauses, do I have to register the table as one name, open it, save a copy of it, close the origina, open the copy and delete the original?!
Unless I am (hopefully) missing something obvious, what an absolute faff!
------------------------------
Ryan Cook
ORH LTD
------------------------------