0

I get this error when running an mbx in Mapbasic

   Include "MapBasic.def"
   Include "Menu.def"

'assign brush/pen symbology for all but easements
        dim b1 as Brush
        b1 = makebrush (1,16777136,-1)  'Black colour, no fill
    dim p1 as Pen
        p1 = makepen (1,2,0)            'Black line
    dim x as Integer
    dim oUpdateObj as Object


    'Change Fill and Pen
    Open Table StrPathOt+"Easements.TAB" Interactive

    'Easements
    Select * from Easements where Str$(obj) = "Region" into NewStyle
        Fetch first from NewStyle
    x = 1
    Do
        oUpdateObj = NewStyle.obj
            Alter Object oUpdateObj Info OBJ_INFO_BRUSH, b1
            Alter Object oUpdateObj Info OBJ_INFO_PEN, p1

            Update NewStyle set Obj = oUpdateObj where RowID = x

            x = x + 1

            Fetch next from NewStyle

    Loop while x <= TableInfo(NewStyle,TAB_INFO_NROWS)
    Commit Table Easements

The issue reported is on this line enter image description here Alter Object oUpdateObj Info OBJ_INFO_BRUSH, b1

2

An alternative to this approach, and a more efficient way to do this as MapInfo can deal with looping through the table internally, is to extract the style update code into a separate function which you can then call directly from an Update Table statement.

Sub Assign_Symbology (ByVal fileName as String, ByVal b1 as Brush, ByVal p1 as Pen)

    Open Table fileName as NewStyle
    Update NewStyle Set obj = UpdateStyle(obj, b1, p1)

End Sub

Function UpdateStyle(ByVal objTarget as Object, ByVal b1 as Brush, ByVal p1 as Pen) as Object

    Alter Object objTarget Info OBJ_INFO_BRUSH, b1
    Alter Object objTarget Info OBJ_INFO_PEN, p1

    UpdateStyle = objTarget

End Function
0

Figured out an answer based on feedback in LI360

Here's the code if anyone is interested.


Declare Sub Assign_Symbology(ByVal FileName as String, ByVal b1 as Brush, ByVal p1 as Pen)

Declare Sub Main


Sub Assign_Symbology (ByVal FileName as String, ByVal b1 as Brush, ByVal p1 as Pen)

Dim   oUpdateObj as Object

Dim x as Integer


Open Table FileName as NewStyle

Fetch first from NewStyle

Do Until EOT(NewStyle)


 oUpdateObj = NewStyle.obj


 x = NewStyle.ROWID


 Alter Object oUpdateObj Info OBJ_INFO_BRUSH, b1


 Alter Object oUpdateObj Info OBJ_INFO_PEN, p1


 Update NewStyle set Obj = oUpdateObj where RowID = x


 Fetch next from NewStyle


Loop

Commit Table NewStyle

Close Table NewStyle

End Sub


Sub Main

Dim StrPathOt, FileName as String

StrPathOt="G:\Projects\076_Monthly_DCDB_Update\Working\current\output\"


   dim b1 as Brush

   dim p1 as Pen

   'Assing file to modify and symbology to set


      'Easements

      FileName = StrPathOt+"Easements.TAB"

      p1 = makepen (1,2,0)         'Black line

      b1 = makebrush (1,16777136,-1)   'Black colour, no fill

      Call Assign_Symbology (FileName, b1, p1)

      Print " Assigned symbology for: "+FileName

      'Drainage

      FileName = StrPathOt+"Drainage_DCDB"

      Call Assign_Symbology (FileName, b1, p1)

      Print " Assigned symbology for: "+FileName

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.