I wanted to create a temporary table as per my variable.

If i have a value of 10, it will create a table with 10 rows.

How should i start my code in MapBasic?


Assuming that you don't have the table yet, you need to start by creating the table itself.

This is done using a MapBasic/basic SQL DDL statement:

Create Table MY_TABLE
   (ID Integer)
   File TempFileName$("")

If you also need to store spatial data in your table, you need to make it mappable, too. When you make it mappable you create the MAP and ID files that MapInfo Pro uses for storing the spatial records. Once the table has been made mappable, you can refer to the spatial part of each record using the OBJ column name.

Often you will refer to an existing table or the current map window for a coordinate system but you can also specify a specific hard coded coordinate system.

Here an example on how to refer to an existing open table:

Create Map
   CoordSys Table SOME_OTHER_TABLE

or a map window

'**Here assuming that the front most window is a map
Create Map
   CoordSys Window FrontWindow()

or here using a specific coordinate system (EPSG:4326):

Create Map       
   CoordSys Earth Projection 1, 104

Now you are ready to insert your values.

If you have an Integer values holding the number of records to create, you can loop over this and insert as many records as needed.

In this example the variable nTheNumberOfRecordsToInsert tells me how many records to insert and i is your loop variable, both should be dim'ed as Integers.

For i = 1 To nTheNumberOfRecordsToInsert
   '**Inserting a record, here the current value of i (1, 2, 3, ...)
   Insert Into MY_TABLE (ID) Values (i)
'**Now let's commit the changes to the table
Commit Table MY_TABLE
| improve this answer | |

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.