0% found this document useful (0 votes)
75 views4 pages

Looping A Table in MapBasic

Looping a table in MapBasic

Uploaded by

Achmad Amrulloh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
75 views4 pages

Looping A Table in MapBasic

Looping a table in MapBasic

Uploaded by

Achmad Amrulloh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

2/3/2021 Looping a table in MapBasic

(http://www.pitneybowes.com/us/support.html)
Support

Looping a table in MapBasic

Products Affected: MapInfo Professional, MapInfo MapBasic

How to loop a table in MapBasic

One of the often used things in MapBasic is to loop thru a table to read values from the table and
then react to or modify these values.
MapBasic has a number of looping methods:

Do Until ... Loop


Do While ... Loop
While ... Wend
For ... Next

However one seems better than the others when it comes to looping a table: Do Until ... Loop. At
least that's the one I have been using for years. You can also use Do
While ... Loop and While ... Wend.
But I will recommend that you stay away from For ... Next when looping thru a table. I'll get back to
why.

Now you need a few other statements as well when looping a table:

Fetch First From some_table_name


Fetch Next From some_table_name
EOT( some_table_name )

Let's try to put all this together:

https://support.pitneybowes.com/VFP05_KnowledgeWithSidebarHowTo?id=kA180000000CtKCCA0&popup=false&lang=en_US 1/4
2/3/2021 Looping a table in MapBasic

Set CoordSys Table MY_TABLE

Fetch First From MY_TABLE


Do Until EOT(MY_TABLE)

nRowID = MY_TABLE.ROWID
oFeature = MY_TABLE.OBJ

Fetch Next From MY_TABLE


Loop

In the example above I loop the table called MY_TABLE. For each record I read the RowID, the
hidden dynamic column referring to a specific post in a table or query, and the spatial object from
the column called OBJ.

Oh, and I set my application to use the same coordinate system as the table before I start looping.
Now this loop doesn't really do anything clever yet. I would need to add my logic just before
the Fetch Next From statement.

I also promised to explain why you shouldn't use the For ... Next loop when working with a table.
The problem isn't as much the loop, but more that people tend to combine this loop with a
different Fetch statement; Fetch Rec nRec From.

Dim nRec, nRowID As Integer,


oFeature As Object

Set CoordSys Table MY_TABLE

For nRec = 1 To TableInfo(MY_TABLE, TAB_INFO_NROWS)


Fetch Rec nRec From MY_TABLE

nRowID = MY_TABLE.ROWID
oFeature = MY_TABLE.OBJ
Next

Don't use this structure!!

This Fetch statement will put the table cursor at a specific row in the table, which in most case is
fine. But it has a drawback; it will fail if the specific row has been deleted. And if you haven't built-in
error handling in your application, the application will crash.

Fetch Next, on the other side, will skip the deleted records during the loop.

UPDATED: December 2, 2019

https://support.pitneybowes.com/VFP05_KnowledgeWithSidebarHowTo?id=kA180000000CtKCCA0&popup=false&lang=en_US 2/4
2/3/2021 Looping a table in MapBasic

_______________________________________________
Did this article answer your question?

Yes No Somewhat

Contact Us
Chat
Live Chat is currently unavailable
Chat is available Mon - Fri, 8am - 8pm ET

Global Contact Us
(http://www.pitneybowes.com/us/contact-dcs.html)

https://support.pitneybowes.com/VFP05_KnowledgeWithSidebarHowTo?id=kA180000000CtKCCA0&popup=false&lang=en_US 3/4
2/3/2021 Looping a table in MapBasic

(http://www.pitneybowes.com/us.html)

About Pitney Bowes

Our Company (http://www.pitneybowes.com/us/our-company.html)


Newsroom (http://news.pb.com/)
Investor Relations (http://www.investorrelations.pitneybowes.com)
Careers (http://www.pitneybowes.com/us/careers.html)
Software Partners (http://www.pitneybowes.com/us/partners/digital-commerce.html)

Shop

Postage Meters (http://www.pb.com/smb/postage-meters)


Online Postage (http://www.pb.com/smb/online-postage-stamps)
Postage Meter Ink (https://www.pitneybowes.us/shop/postage-meter-ink-supplies/shop-by-product/postage-meter-ink/en-
us/storeus)
Mailing Supplies (https://www.pitneybowes.us/shop/ink-and-supplies/shipping-and-packing-supplies/shipping-and-packing-
supplies/en-us/storeus)
Production Mail Repair Parts (https://www.pb.com/MyAccount/DMTPartsHome_12756_11055_-1)

Customer Service

View & Pay Bills (https://www.pitneybowes.us/signin/LoginHome.go?lang=en&country=US&request_locale=en_US)


Product Support (http://www.pitneybowes.com/us/support.html)
Postal Rate Change (http://support.pb.com/ekip/index?page=rate_change)
Sign In to Your Account (https://www.pitneybowes.us/signin/logon.go?request_locale=en_US#/account/login)
Contact Us (http://www.pitneybowes.com/us/contact-us.html)
Envelope Messaging (http://www.pitneybowes.com/us/envelope-messages.html)

Follow Us

©1996-2019 Pitney Bowes Inc. All rights reserved.

Legal (http://www.pitneybowes.com/us/legal.html)
Privacy Statement (http://www.pitneybowes.com/us/legal/privacy-statement.html)
Sitemap (http://www.pitneybowes.com/us/sitemap.html)

https://support.pitneybowes.com/VFP05_KnowledgeWithSidebarHowTo?id=kA180000000CtKCCA0&popup=false&lang=en_US 4/4

You might also like