Cycling

10 views
Skip to first unread message

Five Thumbs

unread,
Nov 16, 2021, 3:39:04 PM11/16/21
to MapInfo-L
I am trying to change the pen colour for each successive call to a procedure that creates an ellipse.  I tried creating an array with the colour names and then use the array name in the Pen clause.  MapBasic does not like it as it expecting a numeric value.  I also tried switching the colour names with the numeric equivilant but it still fails.  I believe it does not like the array name in the clause.  Below is a sample of what I have.  Is there another way to cycle the colours through a predefined list?

Dim ColourArray(3) as String

i=0   'Starts at 0 but is set to 1 before it is used
ColourArray(1)="Black" ColourArray(2)="Red"  ColourArray(3)="Green" 

Sub CreateAggRegions
i=i+1
Create Ellipse Into Variable AggCircle (x1, y1) (x2, y2) 
     Brush (1,White, White) 
     PEN (1, 2, ColourArray(i))     'it does not like the array name in the Pen clause

Insert Into AggRegions(Col1,Col2, obj) Values (RecID, AggPointCount, AggCircle)
If i =3 then i =1 End if 'resets the colour cycling to
End Sub

Uffe Kousgaard

unread,
Nov 17, 2021, 2:51:07 AM11/17/21
to mapi...@googlegroups.com
Hi,

Try changing your array into integers, rather than strings.

ColourArray(1)=Black
ColourArray(2)=Red
ColourArray(3)=Green

These are 3 constants defined in mapbasic.def

Regards
Uffe Kousgaard

--
--
You received this message because you are subscribed to the
Google Groups "MapInfo-L" group.To post a message to this group, send
email to mapi...@googlegroups.com
To unsubscribe from this group, go to:
http://groups.google.com/group/mapinfo-l/subscribe?hl=en
For more options, information and links to MapInfo resources (searching
archives, feature requests, to visit our Wiki, visit the Welcome page at
http://groups.google.com/group/mapinfo-l?hl=en

---
You received this message because you are subscribed to the Google Groups "MapInfo-L" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mapinfo-l+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mapinfo-l/67fe5a21-f828-41db-9c95-df23f359e476n%40googlegroups.com.

Peter Horsbøll Møller

unread,
Nov 17, 2021, 2:56:30 AM11/17/21
to mapi...@googlegroups.com

And try building your pen into a variable with the MakePen function:

 

Include "MapBasic.def"

 

Dim ColourArray(3) As Integer

ColourArray(1)  = BLACK

ColourArray(2)  = RED

ColourArray(3)  = GREEN

 

Dim penNew As Pen

Dim i, nColour As Integer

 

For i = 1 To 10

     nColour    = ((i - 1) Mod 3) + 1

     penNew = MakePen(1, 2, ColourArray(nColour))

     Print penNew

Next

 

Your code might look like this:

 

Include "MapBasic.def"

 

Dim ColourArray(3) As Integer

ColourArray(1)  = BLACK

ColourArray(2)  = RED

ColourArray(3)  = GREEN

 

Sub CreateAggRegions

 

i = i + 1

nColour    = ((i - 1) Mod 3) + 1

penNew = MakePen(1, 2, ColourArray(nColour))

 

Create Ellipse Into Variable AggCircle (x1, y1) (x2, y2)

     Brush (1,White, White)

     Pen penNew

 

Insert Into AggRegions(Col1,Col2, obj) Values (RecID, AggPointCount, AggCircle)

 

End Sub

 

Peter Horsbøll Møller

www.precisely.com

 

Peter Horsbøll Møller
Principal Sales Engineer - Distinguished Engineer

 

From: mapi...@googlegroups.com <mapi...@googlegroups.com> On Behalf Of Uffe Kousgaard
Sent: 17. november 2021 08:51
To: mapi...@googlegroups.com
Subject: Re: [MI-L] Cycling

 

This message originated Externally. Use proper judgement and caution with attachments, links, or responses.

 

Reply all
Reply to author
Forward
0 new messages