none
Convert Visio Style into VB.Net style for bold, italic, underline, etc. RRS feed

  • Question

  • I'm writing a program that takes data from Visio shapes and uses it.   When I take numbers from a visio shape's "Style" cell in the "Character" section, I am looking for a way to interpret that number in VB.NET terms, so that the program will know whether a shape's text is bold,  italic, underlined or any combination of these.

    When bold, italic, and underlined, the value is 39, for example.  How do I translate that into VB.NET terms?

    Is there a formula/method similar the one I use to translate the Visio code for color (a single integer) into three RGB numbers, which VB.NET can understand:

    Dim color As Integer = testShape.CellsSRC(Visio.VisSectionIndices.visSectionCharacter, rowCt, Visio.VisCellIndices.visCharacterColor).ResultIU

    Dim colorSt(2) As String

    colorSt(0) =

    Globals.ThisAddIn.Application.ActiveDocument.Colors(color).Red.ToString

    colorSt(1) =

    Globals.ThisAddIn.Application.ActiveDocument.Colors(color).Green.ToString

    colorSt(2) =

    Globals.ThisAddIn.Application.ActiveDocument.Colors(color).Blue.ToString


    Gina

    Friday, January 24, 2014 8:45 PM

Answers

  • Hi Gina,

    The value represent bold, italic and underline is hexadecimal. You can get detail from figure below hen you convert the 35 or 55 to binary:

    Hope it is helpful.

    Best regards

    Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, January 30, 2014 2:48 AM
    Moderator
  • Very helpful!  Thank you!

    Gina


    Gina

    • Marked as answer by Gina1111 Thursday, January 30, 2014 3:00 PM
    Thursday, January 30, 2014 3:00 PM

All replies

  • Have you tried other combinations of text styles? The binary value of 39 is 100111, so it is possible that some bits are responsible for bold, italic and underline. Try for example to turn bold style off and on and check how the numeric value is changed.

    To construct a Color value from integer, try Color.FromArgb.


    • Edited by Viorel_MVP Sunday, January 26, 2014 11:01 AM
    Sunday, January 26, 2014 11:00 AM
  • Hi Gina,

    I am moving your thread into the General Office Development Forum for dedicated support. Thanks for your understanding.

    Have a nice day,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, January 27, 2014 2:25 AM
  • I've looked into this some, but it doesn't fit Visio's claim that VisBold = 1, visItalic=2, visUnderline = 4, visSmallCaps = 8.    I have bold, italic and underline, which added up to 39. 

    Additionally, when I adjusted the font, the adjusted back, the same styling added up to 55.  So the value seemed to change for the exact same formatting, just by changing it and changing it back.

    I have color working by the methods shown above.  I didn't have luck with the FromArgb.


    Gina

    Monday, January 27, 2014 4:59 PM
  • Hi Gina,

    As far as I know, there is no way to detect whether a shape’s text is bold, italic and underline. Because we can set the part of text to bold like code below:

    Set a = Application.ActivePage.Shapes(1).Characters
    a.Begin = 2
    a.End = 3
    a.CharProps(visCharacterStyle) = visBold

    >> Is there a formula/method similar the one I use to translate the Visio code for color (a single integer) into three RGB numbers, which VB.NET can understand:<<

    After my testing, when we set color for the shape using ResultIU, it is identical to the index of Application.ActiveDocument.Colors. Below is my test code (VBA):

    Application.ActivePage.Shapes(1).CellsSRC(visSectionObject, visRowFill, FillForegnd).ResultIU = 4
    Set Value3 = Application.ActiveDocument.Colors(4)

    And what do you mean the “VB.Net can understand”? The code you provided already transfer the color to the three RGB strings. Did you mean you want to translate the Color into three RGB numbers rather than string? You can refer to the code below:

    Dim blueValue As Integer
            Dim redValue As Integer
            Dim greenValue As Integer
            blueValue = Globals.ThisAddIn.Application.ActiveDocument.Colors(1).Blue
            redValue = Globals.ThisAddIn.Application.ActiveDocument.Colors(1).Red
            greenValue = Globals.ThisAddIn.Application.ActiveDocument.Colors(1).Green

    Also you can you RGB function to translate the three RGB numbers to integer.

    Hope it is helpful.

    Best regards

    Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, January 28, 2014 11:49 AM
    Moderator
  • Thank you, Fei.

    My comments about color translation was poorly worded.  I had already worked the color codes out, so I used that as an illustration in my question above for how I translated Visio's color code into something Visual Basic could understand.  I wanted to know whether there was a similar translation for bold, italic, and underline formatting.

    Gina


    Gina

    Tuesday, January 28, 2014 2:15 PM
  • Hi Gina,

    Sorry for misunderstanding. As far as I know, there is no API we can use to detect whether the text of shape is bold, italic and underline formation. We can only set it through Characters.CharProps Property.

    And you can get the value represent bold, italic and underline via below:

    visCharacterStyle

    2

    visBold
      visItalic
      visUnderLine
      visSmallCaps

    &H1
      &H2
      &H4
      &H8

    Best regards

    Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, January 29, 2014 9:59 AM
    Moderator
  • Thank you.  That's what I've concluded, too.

    It would work, if "Bold/Italic/Underline were reliably = 7 (1+2+4), for example, and Bold/Italic were reliably = 3..  But for some reason, Bold/Italic/Underline is sometimes registered as 39, or 55.  For 55, Bold = 17, Italic=34, and Underline = 4.   And perhaps there are other manifestations, which makes it unreliable for interpreting programmatically.

    Any ideas how these larger numbers are derived in Visio?


    Gina

    Wednesday, January 29, 2014 12:42 PM
  • Try this interpretation:


    Dim style As Integer = . . . . .
    
    Dim is_bold As Boolean = (style And 1) <> 0
    Dim is_italic As Boolean = (style And 2) <> 0
    Dim is_underline As Boolean = (style And 4) <> 0



    • Edited by Viorel_MVP Wednesday, January 29, 2014 2:19 PM
    Wednesday, January 29, 2014 2:17 PM
  • Hi Gina,

    The value represent bold, italic and underline is hexadecimal. You can get detail from figure below hen you convert the 35 or 55 to binary:

    Hope it is helpful.

    Best regards

    Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, January 30, 2014 2:48 AM
    Moderator
  • Very helpful!  Thank you!

    Gina


    Gina

    • Marked as answer by Gina1111 Thursday, January 30, 2014 3:00 PM
    Thursday, January 30, 2014 3:00 PM