Convert style definition to string [MapBasic]

19 views
Skip to first unread message

Marijan

unread,
Feb 1, 2023, 5:13:33 AM2/1/23
to MapInfo-L
I have defined style for MI objects that I insert/edit using MB tool. 
Something like:
Define MMES_SYM (35,16711680,10,"MapInfo Symbols",0,0)

Now, I need to create string that will store this definition.
However it complains about '(' character. 

I tried both with str$(MMES_SYM)and adding quotes at beginning and end, with no luck. Is it possible to this kind of conversion

Peter Horsbøll Møller

unread,
Feb 1, 2023, 6:56:08 AM2/1/23
to mapi...@googlegroups.com

Hi

 

You should be able to convert a string to a Symbol variable.

But the string needs to look like this:

 

Dim symNew As Symbol
Dim sSym As String
sSym
= CurrentSymbol()
symNew
= sSym

 

Alternatively, you can use a function that takes your string and then converts that into a symbol.

In the STYLELib that is part of my MapBasicLib, there are functions that helps you cast from styles to string and from strings to styles.

 

They take a comma separated string with elements and create new styles from these.

 

Here’s one example:

Function STLText2Symbol(ByVal sSymbol As String) As Symbol

 

Dim   arrItems() As String,

      nNumItems As Integer

 

OnError GoTo ErrorOccured

 

STLText2Symbol = CurrentSymbol()

 

      nNumItems = STRINGSplit(sSymbol, ",", arrItems)

 

      If nNumItems = 3 Then

            'MapInfo 3.0 symbol set

            STLText2Symbol = MakeSymbol(Val(arrItems(1)), Val(arrItems(2)), Val(arrItems(3)))

 

      ElseIf nNumItems > 3 Then

            Do Case arrItems(1)

                  Case "1"

                        'MapInfo 3.0 symbol set

                        STLText2Symbol = MakeSymbol(Val(arrItems(2)), Val(arrItems(3)), Val(arrItems(4)))

 

                  Case "2"

                        'TrueType font as the symbol

                        STLText2Symbol = MakeFontSymbol(Val(arrItems(2)), Val(arrItems(3)), Val(arrItems(4)), arrItems(5), Val(arrItems(6)), Val(arrItems(7)))

 

                  Case "3"

                        'Symbol value based on a bitmap file

                        STLText2Symbol = MakeCustomSymbol(arrItems(2), Val(arrItems(3)), Val(arrItems(4)), Val(arrItems(5)))

            End Case

      End If

 

      Exit Function

'-------------------------

ErrorOccured:

      Call ERRCreate(Err(), Error$(), "STLText2Symbol: " & sSymbol)

      Call ERRShow()

      STLText2Symbol = CurrentSymbol()

 

End Function

 

Find the MapBasicLib on Github.

 

 

 

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

 

From: mapi...@googlegroups.com <mapi...@googlegroups.com> On Behalf Of Marijan
Sent: Wednesday, 1 February 2023 11.14
To: MapInfo-L <mapi...@googlegroups.com>
Subject: [MI-L] Convert style definition to string [MapBasic]

 

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

 

--
--
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/4b98de88-b5f5-41a2-ab7c-7b31ae081a62n%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages