News:

BB code in posts seems to be working again!
I haven't turned on every single tag, so please let me know if there are any that are used/needed but not activated.

Main Menu

Conditional text formatting taken to the next step- keyword formatting

Started by PF4VisioGuy, August 09, 2012, 10:24:30 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

PF4VisioGuy

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


PF4VisioGuy

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

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

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

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

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

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

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

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

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

@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

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

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.


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

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

Browser ID: smf (is_webkit)
Templates: 4: index (default), Display (default), GenericControls (default), GenericControls (default).
Sub templates: 6: init, html_above, body_above, main, body_below, html_below.
Language files: 4: index+Modifications.english (default), Post.english (default), Editor.english (default), Drafts.english (default).
Style sheets: 4: index.css, attachments.css, jquery.sceditor.css, responsive.css.
Hooks called: 408 (show)
Files included: 34 - 1306KB. (show)
Memory used: 1263KB.
Tokens: post-login.
Cache hits: 14: 0.00184s for 26,766 bytes (show)
Cache misses: 3: (show)
Queries used: 16.

[Show Queries]