georeference.org
Subscribe to this thread
Home - Scripting / All posts - New programmer question - getting column data into a variable
Ludwig1 post(s)
#07-Feb-10 19:22

Apologies for posting this question. I am newly come to coding for Manifold (I usually use MapBasic or ArcObjects/VBA), and I am having some problem with the basics.

I realise that I have probably read the solution, but I have had trouble understanding. [sigh. trying a new language is hard]. I've been putting of learning the Manifold way, but Manifold is really too useful not to be able to code it.

What I'd like to code is a loop that cycles through all the records in a drawing's table. Each time it gets to a new record I'd like to put one of the record's field data (such as the ID) into a variable.

For instance, say I have a planning zone layer (called Zones) with the following records:

ID, Zone

1, Residential

2, Business

3, Residential

...

n, Open space

Then the code in MapBasic would look like:

Fetch first from Zones

Do while not EOT(Zones)

iCounter = iCounter + 1

Select * from Zones where rowid = iCounter into TempTable

myID = TempTable.ID

'Do something with myID

Fetch next from Zones

Loop

The bit I am having trouble with in Manifold VB script is the bolded part: myID = TempTable.ID

Thanks in advance for your help,

Julie of Leichhardt Council

tjhb

3,200 post(s)
#07-Feb-10 20:40

It's not the only way to do it, and not very robust. For one thing there is no rowid in Manifold accessible to SQL. (SQL rows are not inherently ordered.)

But assuming you had created a table called "TempTable" with just one row, containing all the columns from the drawing "Zones" (including the ID column), as in the example, you'd use something like this:

myID = Document.ComponentSet("TempTable").RecordSet(0).Data("ID")

It would be better and simpler to skip the query and its TempTable entirely, and replace the two lines

Select * from Zones [...]

myID = TempTable.ID

with

myID = Document.ComponentSet("Zones").RecordSet(iCounter).Data("ID")

[Corrected and expanded.]

KlausDE

4,178 post(s)
#09-Feb-10 03:05

But be warned. TempTable.ID never will be your ID, it's manifolds ID and manifold will change it when it needs to.

For example a Union with another feature or a Normalize on the complete drawing will delete the former record with it's old ID with add a new record and a new ID and a copy of the column content according to the setting of transfer rules. All references based on ID will be broken. For this typ of identifier you will have to add and maintain your own ID in the original table.

0 msec Copyright (C) 2007-2008 Manifold.net. All rights reserved.