1

I have a project which I am reviving after a gap of some years. It involves several hundred runs within MapInfo, scripted in MapBasic.

I am stuck at a point that is so simple, it's driving me nuts.

At one point within each run, I have six tables, each of a single cell.

These tables are called:

minBNGy maxBNGx minBNGy maxBNGy medBNGx medBNGy

They are min, max and median British National Grid coordinates. Each table is mappable, with a single point.

In each case, the table's single variable has the same name as the table.

Each is a long integer, but for some (probably deliberate) reason I no longer understand, I created these as floats.

I need to compile from these six tables a single table, with the six named cells and their values on a single row. It does not need to be mappable.

I was using this:

Add Column TARGET_TABLE (NEW_VARIABLE)From SOURCE_TABLE 
   Set To SOURCE_VARIABLE 
   Where COL1 = COL1

... but it no longer seems to work.

In my old code, the 'map' was dropped later.

I am using MapInfo / MapBasic v.6.5 on Windows 7 Ultimate 64-bit.

I would be very grateful for any guidance.

Bruce

  • how does it now longer work? What happens or what doesn't happen? – Peter Horsbøll Møller Mar 11 '15 at 12:40
  • Sorry - I did not make that clear. The TARGET_TABLE is created all right, but the respective NEW_VARIABLE cells are populated with zero. – Bruce Mitchell Mar 11 '15 at 21:20
  • 1
    Is your variable SOURCE_VARIABLE defined as an Alias variable? I think you need to point that at the table and column or your source table, like Dim aSource As Alias aSource = SOURCE_TABLE + "." + SOURCE_VARIABLE – Peter Horsbøll Møller Mar 13 '15 at 7:30
  • 1
    Would you be able to share you full source code? – Peter Horsbøll Møller Mar 31 '15 at 8:28
  • 1
    sure, send it to: peter.moller at pb.com – Peter Horsbøll Møller Apr 1 '15 at 15:23
1

The solution was derived with assistance from Peter Horsbøll Møller:

' ================================================

'   CALCULATE MIN AND MAX X COORDINATES OF CLUSTER

Open Table Spy60_O as Spy60 Interactive

Dim fMinX As Float
Select * from Spy60 order by caseNo into xSorted
Browse * From xSorted
Fetch First From xSorted
fMinX = xSorted.BNGx
Close Table xSorted 

Dim fMaxX As Float
Select * from Spy60 order by caseNo Desc into xReverseSorted
Browse * From xReverseSorted
Fetch First From xReverseSorted
fMaxX = xReverseSorted.BNGx
Close Table xReverseSorted 

'   CALCULATE MIN AND MAX Y COORDINATES OF CLUSTER

Dim fMinY As Float
Select * from Spy60 order by caseNo into ySorted
Browse * From ySorted
Fetch First From ySorted
fMinY = ySorted.BNGy
Close Table ySorted 


Dim fMaxY As Float
Select * from Spy60 order by caseNo Desc into yReverseSorted
Browse * From yReverseSorted
Fetch First From yReverseSorted
fMaxY = yReverseSorted.BNGy
Close Table yReverseSorted 


' ================================================
'
'   CALCULATE MEDIAN CENTRE X AND Y COORDINATES OF CLUSTER
'
'from: http://testdrive.mapinfo.com/TECHSUPP/MIPROD.NSF/59d125f456480edb852562b5004f2c33/daeed8326071ce0c85256b89005a72ad?OpenDocument
'
' ================================================
'

Browse * From Spy60
dim MedianTableX as string, ColNameX as string, nX as integer
MedianTableX="exTable"
ColNameX="exColumn"
Select BNGx from Spy60 Order By BNGx Into MedianTempX NoSelect
nX=TableInfo(MedianTempX, 8)
Select Avg(BNGx)from MedianTempX where RowID=int((nX+1)/2) or RowID=int((nX+2-(nX mod 2))/2) into MedianFinalX NoSelect
Browse * from MedianFinalX
Commit Table MedianFinalX As medBNGx_O
Open Table medBNGx_O as medBNGx Interactive

Dim fMedX As Float
fMedX  = medBNGx._COL1


Browse * From Spy60
dim MedianTableY as string, ColNameY as string, nY as integer
MedianTableY="exTable"
ColNameY="exColumn"
Select BNGy from Spy60 Order By BNGy Into MedianTempY NoSelect
nY=TableInfo(MedianTempY, 8)
Select Avg(BNGy)from MedianTempY where RowID=int((nY+1)/2) or RowID=int((nY+2-(nY mod 2))/2) into MedianFinalY NoSelect
Browse * from MedianFinalY
Commit Table MedianFinalY As medBNGy_O
Open Table medBNGy_O as medBNGy Interactive

Dim fMedY As Float
fMedY  = medBNGy._COL1

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.