MapBasic - Fetch command - Open tables Loop

733 views
Skip to first unread message

Jamie

unread,
Jun 15, 2015, 6:32:54 AM6/15/15
to mapi...@googlegroups.com
Not sure if i'm using the wrong command here.

I have a table where the only browser field is a file path to a raster dataset.
When elements of this table are selected i want to loop through the selection and open all tables listed i'm trying to use the fetch command however this just keeps coming up with a note box stating the file path.

Is there a different command i need to use to do this?

I've managed something similar in the past with the help of the group to export my selection as a text file and import my files that way - thought if it was possible to bypass this step it would make my tool more efficient.

Example File
Path
X:\Folder_1\Tile_1.tab
X:\Folder_2\Tile_1.tab
X:\Folder_2\Tile_2.tab

Sub Load

Dim i As Integer
Dim oPath As String

i
= 0

Fetch First from TABLE_Selection
Do While Not EOT(TABLE_Selection)
i
= i + 1
oPath = """Open Table """ & COL1 & """ Interactive"""

Run Command oPath
Fetch Next from TABLE_Selection
Loop

End Sub



Jamie

unread,
Jun 15, 2015, 6:46:06 AM6/15/15
to mapi...@googlegroups.com
I've found a section in the MapBasicUserGuide (12.5.1 pg. 134) that suggests the below code which is slightly different.

All that happens when i run the code is i get 2 note boxes pop up with the paths of the two selected elements

Sub Load

Dim i As Integer
Dim tPath As String

Dim oPath As String

i = 0

Fetch First from
TABLE_Selection
Do While Not EOT(
TABLE_Selection)

i = i + 1
tPath = TABLE_Selection.Path
oPath = """Open Table """ & tPath & """ Interactive"""

Run Command oPath
Fetch Next from
TABLE_Selection
Loop

End Sub


Peter Horsbøll Møller

unread,
Jun 15, 2015, 7:27:43 AM6/15/15
to mapi...@googlegroups.com
Try one of these two:

oPath = "Open Table " & Chr$(34) & tPath & Chr$(34) & " Interactive"
Run Command oPath

or

Open Table tPath Interactive

Peter Horsbøll Møller
Pitney Bowes Software



Date: Mon, 15 Jun 2015 03:46:06 -0700
From: jamie...@gmail.com
To: mapi...@googlegroups.com
Subject: [MI-L] Re: MapBasic - Fetch command - Open tables Loop
--
--
You received this message because you are subscribed to the
Google Groups "MapInfo-L" group.To post a message to this group, send
email to mapi...@googlegroups.com
To unsubscribe from this group, go to:
http://groups.google.com/group/mapinfo-l/subscribe?hl=en
For more options, information and links to MapInfo resources (searching
archives, feature requests, to visit our Wiki, visit the Welcome page at
http://groups.google.com/group/mapinfo-l?hl=en

---
You received this message because you are subscribed to the Google Groups "MapInfo-L" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mapinfo-l+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jamie

unread,
Jun 15, 2015, 7:51:38 AM6/15/15
to mapi...@googlegroups.com
both of these still only give me a pop up box with the file path in it. - i have no note statements.

Jamie

unread,
Jun 15, 2015, 8:04:13 AM6/15/15
to mapi...@googlegroups.com
I'm getting closer to an answer with this using the "For" command however this only opens the file that's the first row of the table

i can't seem to make it loop through the whole selection. i've tried a few variations on the Do While statement but i either get errors on compiling or infinite loops so MapInfo crashes.

Using fetch i couldn't stop just getting pop up boxes so is there more chance i'll get this method to work.

Dim i As Integer
Dim iRecord As Integer
Dim tPath As String

'Do While NOT EOT(TABLE_Selection)

i = 1
For iRecord = i to TableInfo(
TABLE_Selection,TAB_INFO_NROWS)

i = i + 1
tPath = TABLE.COL1
Open Table tPath Interactive
Next

'
Loop


Jamie

unread,
Jun 15, 2015, 8:07:59 AM6/15/15
to mapi...@googlegroups.com
ah think i've solved it i've added a fetch next statement in at the end of the section and that seems to work



Dim i As Integer
Dim iRecord As Integer
Dim tPath As String

i = 1
For iRecord = i to TableInfo(
TABLE_Selection,TAB_INFO_NROWS)
i = i + 1
tPath =
TABLE.COL1
Open Table tPath Interactive
 
Fetch Next From TABLE_Selection

 
Next



Peter Horsbøll Møller

unread,
Jun 15, 2015, 8:13:56 AM6/15/15
to mapi...@googlegroups.com

Ah, I didn’t see that you were missing the Fetch Next statement.

 

I would recommend that you go back to the Do structure. Otherwise you might run into problems if you have deleted records in your table:

 

Fetch First from TABLE_Selection

Do While NOT EOT(TABLE_Selection)



   tPath = TABLE.COL1
   Open Table tPath Interactive

   Fetch Next from TABLE_Selection

Loop

 

Peter Horsbøll Møller

Pitney Bowes

 

--

--
You received this message because you are subscribed to the
Google Groups "MapInfo-L" group.To post a message to this group, send
email to


To unsubscribe from this group, go to:
http://groups.google.com/group/mapinfo-l/subscribe?hl=en
For more options, information and links to MapInfo resources (searching
archives, feature requests, to visit our Wiki, visit the Welcome page at
http://groups.google.com/group/mapinfo-l?hl=en

---
You received this message because you are subscribed to the Google Groups "MapInfo-L" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mapinfo-l+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jamie

unread,
Jun 15, 2015, 8:21:03 AM6/15/15
to mapi...@googlegroups.com
thanks again peter :)
Reply all
Reply to author
Forward
0 new messages