Author Topic: Conditional text formatting taken to the next step- keyword formatting  (Read 10762 times)

0 Members and 1 Guest are viewing this topic.

PF4VisioGuy

  • Full Member
  • ***
  • Posts: 100
Hi all

I am using Visio 2010 to create some cheat sheets for my exams.
My problem is this: I need to create a shape (text square) that would automatically format keywords either while I am editing of after I exited the editting mode.

Ex: let's assume that my key words are "Visio" "Excel" "Outlook" "PowerPoint".
I need that every time when a text shape contains these words they should be automatically formatted like bold (Visio, Excel. Outlook, PowerPoint)

How can I do that? I should tell you that my key word list might become pretty big in time.

thanks
PF

PS: the "next step" in the subject line refers to this thread http://visguy.com/vgforum/index.php?topic=239.msg1010#msg1010
« Last Edit: August 09, 2012, 06:25:40 AM by PF4VisioGuy »

aledlund

  • Hero Member
  • *****
  • Posts: 1412
Re: Conditional text formatting taken to the next step- keyword formatting
« Reply #1 on: August 09, 2012, 06:47:04 AM »
You might check this out for an introduction to what you're attempting to do
http://blogs.msdn.com/b/visio/archive/2006/08/18/running-with-characters.aspx
al

PF4VisioGuy

  • Full Member
  • ***
  • Posts: 100
Re: Conditional text formatting taken to the next step- keyword formatting
« Reply #2 on: August 09, 2012, 08:12:43 AM »
Thanks aledlund, I saw that one but...it is to elaborate for me. Also it is C++.
I was hoping for something simpler. Any other suggestions?

aledlund

  • Hero Member
  • *****
  • Posts: 1412
Re: Conditional text formatting taken to the next step- keyword formatting
« Reply #3 on: August 09, 2012, 10:05:39 AM »
Unfortunately 'text runs' are the way that Visio format's it's text. Admittedly it's not a pretty picture to build programmatically. You're going to have to write code that parse's out your text string to find your keywords and then based upon the text add/update the appropriate rows in the shapesheet. The text run can have a mixture of character, paragraph, tab, and field properties/rows assigned to each of the substrings that you want to work with.  The code example by the way was C# and their are free utilities to convert to VB.Net (which is close enought to VBA to make an easy translation).

Al

PF4VisioGuy

  • Full Member
  • ***
  • Posts: 100
Re: Conditional text formatting taken to the next step- keyword formatting
« Reply #4 on: August 09, 2012, 10:14:10 AM »
Hi Al

Thanks again
The solution you are indicating contains to many unknown factors for me.
I was hoping for a simpler solution, a sort of search string function that would find the position of the word in the string and change the formating.
At this moment I am wondering if there is any interface between Perl and Visio probably that would work easier since Perl has advanced string search capabilities

aledlund

  • Hero Member
  • *****
  • Posts: 1412
Re: Conditional text formatting taken to the next step- keyword formatting
« Reply #5 on: August 09, 2012, 10:47:48 AM »
It doesn't really matter what you write it in, the formatting of the substrings is handled in the shapesheet with a discreet row in the character section for every change you want to make in the string. The formatting is not embedded in the text string.
al

PF4VisioGuy

  • Full Member
  • ***
  • Posts: 100
Re: Conditional text formatting taken to the next step- keyword formatting
« Reply #6 on: August 09, 2012, 11:03:28 AM »
True, but let's not forget how powerful Perl is when it comes to searching strings, returning results (position of the matches in the text and so on)
I was hopping that Perl will reduce/hide the complexity of the search algorithm

aledlund

  • Hero Member
  • *****
  • Posts: 1412
Re: Conditional text formatting taken to the next step- keyword formatting
« Reply #7 on: August 09, 2012, 11:24:42 AM »
IMHO the search algorithm is the least of your worries because generic searchs are fairly easy.
for each shape in page.shapes
 parse text into list/array of strings
 for each substring in list
   for each keyword in kwlist
     if keyword = substring then
      go do subroutine to update shape character section
    end if
   next keyword
next substring
next shape

al

PF4VisioGuy

  • Full Member
  • ***
  • Posts: 100
Re: Conditional text formatting taken to the next step- keyword formatting
« Reply #8 on: August 09, 2012, 11:52:34 AM »
I would not go that way, that is too complicated
I would create a shape with a procedure attached to the "FinishedEditing" event
When that is done the search and format procedure should kick in and do its job.


vojo

  • Hero Member
  • *****
  • Posts: 1711
Re: Conditional text formatting taken to the next step- keyword formatting
« Reply #9 on: August 09, 2012, 01:10:55 PM »
if the set of keywords are small enough.....say 10....you can do this in the shapesheet

prop.keyword = <word used>
user.blold = if(strsame(<word used>), <word1>,1,if(strsame(<word used>,<word2>),1,if.....                                              1,0)))))
fontbold = if(user.bold =1, 1, 0)

If you want word 1, word 2, etc dyname....set props cells for them and compare to them instead of static values   (props.word1, props.word2, etc)

If at the page level...set there and have shapes compare those values....might be a bit tough with stencils holding original shapes...but since special cells at page level, talking template anyway

wapperdude

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4882
  • Ideas Visio-lized into solutions
Re: Conditional text formatting taken to the next step- keyword formatting
« Reply #10 on: August 09, 2012, 08:34:40 PM »
Sounds like you'll spend more time making your study sheets than you will studying.  Not sure why you'd do this in Visio?

There are a lot of flashcard options on the internet, geared to making study cards for tests.  Many are free.  You might want to check those out and save valuable time.

Wapperdude
Visio 2019 Pro

PF4VisioGuy

  • Full Member
  • ***
  • Posts: 100
Re: Conditional text formatting taken to the next step- keyword formatting
« Reply #11 on: August 10, 2012, 02:52:24 PM »
@wapperdude:  there is a slight difference between flash cards and cheat sheets. I need to create cheat sheets.

@vojo: I am lost in parentheses :-)) can you reduce your example at just two key words please and implement the formulae completely so I can understand them

everbody: thaks for all the suggestions so far.


wapperdude

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4882
  • Ideas Visio-lized into solutions
Re: Conditional text formatting taken to the next step- keyword formatting
« Reply #12 on: August 10, 2012, 03:59:41 PM »
Differences noted. 

But, in my opinion, Visio is the wrong tool.  Manipulating text as you desired is not a simple task as others have already indicated.  Visio is a graphics tool.  Do you plan to use graphics?

For text manipulation it would seem like some word processing application would be better.  Then, you have a decent shot at interfacing with Perl, or writing a macro to do search and replace using a list of your keywords as search criteria, or something using a C-derivative program.

You don't need to respond to these observations, I'm just throwing out ideas to help you direct your energies in the most effective way.

Wapperdude
Visio 2019 Pro

Jumpy

  • Hero Member
  • *****
  • Posts: 1061
Re: Conditional text formatting taken to the next step- keyword formatting
« Reply #13 on: August 10, 2012, 05:23:36 PM »
The following code was used to find words in a selected text and format them differently. Maybe that get's you started:
Sorry for the german annotaions, it's to late in the day for me and I#m to tired to translate them.

Code
Sub SelctionFormatierung()

  Dim Start As Integer, Beginn As Integer, Ende As Integer, RowNum As Integer
  Dim vsoCharacters1 As Visio.Characters
  Dim ColorCell As Visio.Cell
  Dim shp As Visio.Shape

On Error GoTo Ende

    'Markierten Text in Characters1 speichern
    Set vsoCharacters1 = Application.ActiveWindow.SelectedText
   
    'Das zum Text gehörende Shape in shp speichern
    Set shp = vsoCharacters1.Shape
   
    'Schriftfarbe festlegen
    vsoCharacters1.CharProps(visCharacterColor) = 12
    RowNum = vsoCharacters1.CharPropsRow(visBiasLeft)
    Set ColorCell = shp.CellsSRC(visSectionCharacter, RowNum, visCharacterColor)
    ColorCell.Formula = "ThePage!User.MyColor"                                     'entspricht "RGB(153; 2; 116)"
       
    'Schriftart festlegen
    vsoCharacters1.CharProps(visCharacterFont) = 64                                     'entspricht Swis721 Bk
   
    'Begin und Ende des markierten Bereichs merken
    Beginn = vsoCharacters1.Begin
    Ende = vsoCharacters1.End
   
    'Auf Mix, mix, Box, box, val testen und dann unten...
    Start = InStr(1, vsoCharacters1.Text, "Mix")
    If Start < 1 Then
      Start = InStr(1, vsoCharacters1.Text, "mix")
    End If
    If Start < 1 Then
      Start = InStr(1, vsoCharacters1.Text, "box")
    End If
    If Start < 1 Then
      Start = InStr(1, vsoCharacters1.Text, "Box")
    End If
    If Start < 1 Then
      Start = InStr(1, vsoCharacters1.Text, "val")
    End If
   
    '...kursiv machen
    If Start > 0 Then
    vsoCharacters1.Begin = Beginn + Start - 1
    vsoCharacters1.End = Beginn + Start + 2     ' or Len("Mix")-1
    vsoCharacters1.CharProps(visCharacterStyle) = 34
    End If
   
    'Zurücksetzen
    vsoCharacters1.Begin = Beginn
    vsoCharacters1.End = Ende
   
    '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   
    'Nach × (Alt+0215) suchen (z.B. in 3×4) und...
    Start = InStr(1, vsoCharacters1.Text, "×")
   
    '...kursiv machen
    If Start > 0 Then
    vsoCharacters1.Begin = Beginn + Start - 2
    vsoCharacters1.End = Beginn + Start + 1
    vsoCharacters1.CharProps(visCharacterStyle) = 34
    End If

    'Zurücksetzen
    vsoCharacters1.Begin = Beginn
    vsoCharacters1.End = Ende
   
    '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   
    'Auf jet und sys testen und dann unten...
    Start = InStr(1, vsoCharacters1.Text, "jet")
    If Start < 1 Then
      Start = InStr(1, vsoCharacters1.Text, "sys")
    End If
   
    '...kursiv machen
    If Start > 0 Then
    vsoCharacters1.Begin = Beginn + Start - 1
    vsoCharacters1.End = Beginn + Start + 2
    vsoCharacters1.CharProps(visCharacterStyle) = 34
    End If

Ende:
End Sub

vojo

  • Hero Member
  • *****
  • Posts: 1711
Re: Conditional text formatting taken to the next step- keyword formatting
« Reply #14 on: August 11, 2012, 06:04:19 PM »
double click the box to get you started

This is the nut of it all.

If you want build up or tear down strings to find words, use the various text functions and operators in the shapesheet