I've problem with my code in MapBasic for change region style in MapBasic.
I've created voronoi and I want to select that voronoi and change the style of it to yellow border and no fill. I already try a code to change that color which I got it from other source but it takes a long time more than I change it manually from MapInfo and when I try to run it becomes not responding.
This is my code
Sub Voronoi
Create Table "voronoi"
(Block_no Char(15),Remark Char(10),Type_Palm Char(10),Ha Float)
File "D:\voronoi.TAB"
TYPE NATIVE Charset "WindowsLatin1"
Create Map For voronoi CoordSys Earth Projection 1, 104
Create Index On voronoi (Block_no)
Add Map Layer voronoi
Set Map Layer 1 Editable On
Create Object As Voronoi from sensus Into Table voronoi
Update voronoi Set Ha = Area(obj, "sq m")
select * from voronoi
where Ha >= Val(inputnumber)
into Selection
Call ChangeColor
Browse * from Selection
End Sub
Sub ChangeColor
Fetch first from Selection
x = 1
Do
oUpdateObj = Selection.obj
b1 = Makebrush (1, 0, 16777215) '<--- Change values for your style
p1 = MakePen(1, 2, 16776960) '<--- Change values for your style
Alter Object oUpdateObj Info OBJ_INFO_BRUSH, b1
Alter Object oUpdateObj Info OBJ_INFO_PEN, p1
Update Selection
Set Obj = oUpdateObj
where RowID = x
x = x + 1
Fetch next from Selection
Loop while x <= TableInfo(Selection,TAB_INFO_NROWS)
End Sub
Best Answer
You don't specify exactly where your tool get slow, but I have a few suggestions to improve the speed.
Implementing these suggestions will make your code look like this: