Latest Visio Version not handling VBA changing character size

Started by paulv45, April 20, 2022, 02:10:55 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

paulv45

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

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

@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

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

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

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

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

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

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

@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

Quote from: paulv45 on June 02, 2022, 03:30:16 PM
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

paulv45

@Surrogate
@wapperdude
@yacine
Sorry I have been silent.
Thanks for jumping in, Surrogate.

In my project log it looks like I did use the Feedback machinery to make input to MS 4/29/2022.
Heard nothing back.
Don't know if related, but I happy to report for me the problem is resolved in 2207.
Hope it stays fixed.

wapperdude, you might want to give it a check for your app.

Paul


wapperdude

Thank you for getting back to us.  Yes.  The new update seems to have fixed the problem.  The code runs fine now.

Cheers!
Visio 2019 Pro