Author Topic: Latest Visio Version not handling VBA changing character size  (Read 2431 times)

0 Members and 1 Guest are viewing this topic.

paulv45

  • Jr. Member
  • **
  • Posts: 51
Re: Latest Visio Version not handling VBA changing character size
« Reply #45 on: May 09, 2022, 09:17:45 PM »
Wondering if others could suggest fixes related to runs when stepping using <f8> I posted in Programming & Code:
What does in mean when code runs in debug but not in operation?

Yacine also responded there suggesting (as also in this thread) DoEvents before and after:
objChar.CharProps(visCharacterSize) = 8#
Tried both before and after and that worked.  Just before also works. Just after does not.

So conclusion is that something deep down in Visio did indeed change some time after 2108 -- not really a bug, just a change.
And we have a fix.

I'll continue to work to be sure everything is solid, but pretty confident it is.  Will report back if not.

Thanks so much for hanging in there with me on this Yacine and wapperdude.  Your help is very much appreciated.

vojo

  • Hero Member
  • *****
  • Posts: 1657
Re: Latest Visio Version not handling VBA changing character size
« Reply #46 on: May 10, 2022, 07:15:39 AM »
One suggestion would be to move the scaling out of this

user.scale = width/predefined width.     

For example, lets say the idea with is 20mm....then user.scale = width/20mm....if width 20mm....the char is 8pt * 2

Character = 8pt * user.scale

So if you want to change the font scale, your vba could modify or replace the value in user.scale without touching the char cell


wapperdude

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4331
  • Ideas Visio-lized into solutions
Re: Latest Visio Version not handling VBA changing character size
« Reply #47 on: May 10, 2022, 11:44:41 AM »
@Vojo:  the reason for touching the char.size cell was to only change specific characters within the string, not the entire string.

@ Yacine, paulv45:  retried the DoEvents, both the original macro and my looping macro.  Both failed to work correctly with DoEvent functions.  Note, the only time it works presently is during the record macro phase.
Visio 2019 Pro

wapperdude

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4331
  • Ideas Visio-lized into solutions
Re: Latest Visio Version not handling VBA changing character size
« Reply #48 on: May 11, 2022, 07:16:27 PM »
Tried something different, for sanity check.  After setting char begin & end, instead of using '.charProps(...)' , I used  '.Text = "NewTxt"'.  This replaces the portion of the text string identified by the begin/end value assignment with NewTxt.  That works fine.  Then I added another line, using char props to make new text bold.  All text became bold.

Looking at shapesheet, there's only the single row in the Characters section.  Visio isn't doing any parsing.  Oh. Plus, Visio doesn't allow you to manually add rows to this section.
Visio 2019 Pro

vojo

  • Hero Member
  • *****
  • Posts: 1657
Re: Latest Visio Version not handling VBA changing character size
« Reply #49 on: May 12, 2022, 09:15:25 AM »
isnt charsize for ALL characters?

are you suggest some sort of group if child shapes, each one wih 1 character?

I am not aware of 5 char. size cells for "hello" in 1 shape,,,nor how to map each to a char (1st to 1st?)

wapperdude

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4331
  • Ideas Visio-lized into solutions
Re: Latest Visio Version not handling VBA changing character size
« Reply #50 on: May 12, 2022, 10:46:51 AM »
The Characters section of shapesheet holds all manner of formatting of text. 
Typically, the formatting is applied to the entire text string.  Indeed, when you add text to a shape, there is but a single row in this section, and what might, euphemistically, be called the row name, indicates the character count. 

But, if you identify a portion of the string, i.e., a single letter, a word, or a group of words, you can create a "localized" formatting for the selection, e.g., make it bold, different color,.  When such localized for mating occurs, Visio adds one or more rows to the the character section.  Each row signifies the appropriate formatting applied to the number of characters in that row.

This is easily demonstrated.  Put a shape on drawing page, open shapesheet, and arrange both windows for viewing.  Scroll to the Character section to view it.  Now, enter some text into the shape, and the row fills in.  Select a word and make it bold.  Watch Visio add rows, change text properties/formatting.   

Doing this programmaticly is the heart of this discussion.  It is a process that both myself and the OP have successfully used in the past, but now fails.  Yacine has not encountered the problem, but suggested a "fix".  The fix seems to work for the OP, but not for me.  All of this used to work until recently.  Something has changed.

The mechanism for doing this is easily obtained using video recorder...and in that mode, it works for me.  There is also code postings above.  I've included code posts that step thru the entire text string, searching for all occurrences of a specified character combo.  The localized portion of the string is established by the char.begin and char.end fcns, and applied using char.props method.  See:
https://docs.microsoft.com/en-us/office/vba/api/visio.characters.begin
https://docs.microsoft.com/en-us/office/vba/api/visio.characters.charprops

So, no grouping employed.
Visio 2019 Pro

vojo

  • Hero Member
  • *****
  • Posts: 1657
Re: Latest Visio Version not handling VBA changing character size
« Reply #51 on: May 12, 2022, 01:15:30 PM »
ok...works...but kludgy
- its based on groups of characters
      For example " hello" would have 3 rows
          Row 1 for he
          Row 2 for LL
          Row 3 for o
       so basically its along the line of "changes in character format==>new row"
- since no directly specified linkage, some body would need a master shape with each character called out.
       in this example,  5 rows...always know its five so "XXXXX"
          Then could program row 3,4 as appropriate....e.g  "XXXXX"...dont know how to programitcally pick chars 3,4 to force row calculus to allow program changes for those characters.

bottom line:  great for UI...butt tough programmatically

maybe thetext = user.1+user.2+user3+user.4+user.5....maybe that would trigger 5 rows
Oherwise...group of child shapes
         

wapperdude

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4331
  • Ideas Visio-lized into solutions
Re: Latest Visio Version not handling VBA changing character size
« Reply #52 on: May 12, 2022, 02:42:17 PM »
Actually, not that tough to do coding.

For instance, my code loops thru the string to search for something and then edit what you find.

If you have a multi-formatted string, you loop thru the rows of the section and then do what you want.

For more code examples:  http://visguy.com/vgforum/index.php?topic=7638.msg32400#msg32400
Visio 2019 Pro

paulv45

  • Jr. Member
  • **
  • Posts: 51
Re: Latest Visio Version not handling VBA changing character size
« Reply #53 on: May 14, 2022, 01:09:25 PM »
Based on further experiments and wapperdude's work, I am not convinced that
simply adding DoEvents before every CharProps call will always work.

Conclusions so far...

- Based on wapperdude and my experience there is a bug manifesting itself
   in the handling of the Characters.CharProps property.

- This bug was not present in the 2108 release and in releases prior to that.

- Can't say when it was introduced, but exists in 2203 and 2204 releases.

- While the bug exhibits itself in Characters.CharProps property, it seems
   likely that a change someplace else causes CharProps to behave badly.

- The behavior is subtle and we do not yet have a simple test case.

- In one example adding DoEvents prior to Characters.CharProps solves the
   problem.

- It is likely that given sufficient time a simple test case can be created.

- Evidence of the problem shows up in the Character rows of the ShapeSheet.

The burning questions...

If we were able to make Microsoft aware of the problem would it likely be fixed?

If so, what is the mechanism to make Microsoft aware of the problem?

Any thoughts?


paulv45

  • Jr. Member
  • **
  • Posts: 51
Re: Latest Visio Version not handling VBA changing character size
« Reply #54 on: June 02, 2022, 10:30:16 AM »
@wapperdude
@yacine
I was a bit surprised at no responses to my last post.
I am assuming in fact there is no way to report a problem to MS with any hope of fixing.
I am proceeding with DoEvents before Characters.CharProps calls with hope this always work (thanks again yacine).
Thanks to both of you for helping me.

Surrogate

  • Hero Member
  • *****
  • Posts: 1534
    • ShapeSheet™ Knowledge Base
Re: Latest Visio Version not handling VBA changing character size
« Reply #55 on: June 02, 2022, 10:42:02 AM »
I am assuming in fact there is no way to report a problem to MS with any hope of fixing.
I know few ways:
1. feedbackportal.microsoft.com,  there you can leave your wishes and suggestions. if your appeal is supported by many users - MS [probably] will try to implement it.
2. In the Visio team's blog entries, they indicate the e-mail: tellvisio@microsoft.com.
3. If you use Visio Plan 2, in the interface you can find a button with a smile to send your message: sad smiley - report a problem
« Last Edit: June 02, 2022, 10:45:32 AM by Surrogate »