0

How do I print a tables information in Mapbasic? I have a snippet of code - I want to select all features within a buffer and then print the results as a message in mapinfo that can be copied out into word.

Select * from Land_charges_test
Create Object As Buffer From Selection Width 500 Units "m" Type Spherical 
   Resolution 100 Into Table Land_charges_test Data ID=ID,Tree=Tree

Select * from tree, Land_charges_test 
   where tree.Obj Within Land_charges_test.Obj into Selection
Browse * From Selection

**Print Selection**

It's the print selection function I need, but cannot find

1

The print command doesn't really work like that, you can't print a selection or table. You can print the value held in a field of a specific record though, so what you want to do is build a string for each record and then print that string.

e.g.

Dim nCols, i as Integer
Dim colAlias as Alias
Dim str as String

Select * from Land_charges_test Create Object As Buffer From Selection Width 500 Units "m" Type Spherical Resolution 100 Into Table Land_charges_test Data ID=ID,Tree=Tree

Select * from tree, Land_charges_test where tree.Obj Within Land_charges_test.Obj into Selection 

Browse * From Selection

nCols = NumCols(Selection)

Fetch first from Selection
Do While Not EOT(Selection)
    For i = 1 to nCols
        colAlias = "Selection.COL" & i
        str = str & colAlias
        If i < nCols then
            str = str & " | "
        End if
    Next
    Print str
    Fetch Next from Selection
Loop

Note, I haven't tested the code and it's been a while since I've used MapBasic so please excuse if there are any errors but this should give you the gist of what you need to do.

  • Thank you. I will have to try this at home. From what I can tell, the "Do While Not EOT(Selection)" and other statements can only be run from an addon once compiled and not via the mapbasic window in mapinfo – Jonathan West Jun 7 '18 at 9:11
  • Yes, that's correct, you'll have to compile the code for this to work. – T_Bacon Jun 7 '18 at 13:09
  • 1
    By the way, have you tried copying directly from a browser window? – T_Bacon Jun 7 '18 at 13:10
  • As in copy paste the selected values from the browser window into a word/excel document? I was hoping that once i've managed to "print" one table into the message window, it'll carry on through other operations and print them into the message window too (i.e. query the tree layer, then query layer x, then query layer y etc). Once it's queried all the layers, the relevant info has been printed to the message window ready for copying into word or excel – Jonathan West Jun 11 '18 at 15:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.