Author Topic: Type safety in VB.NET and Visio cells  (Read 2505 times)

0 Members and 1 Guest are viewing this topic.

Visisthebest

  • Sr. Member
  • ****
  • Posts: 376
Type safety in VB.NET and Visio cells
« on: May 02, 2021, 04:12:29 AM »
In most VB.NET add-in code I am calculating with doubles.

When reading Cell.Result it is unclear which VisUnitCodes option makes sure that I am getting a double (not in any specific units, just a number from a shapesheet formula).

I could add a CDbl around it to force a double type whatever is returned:
https://docs.microsoft.com/en-us/office/vba/language/concepts/getting-started/type-conversion-functions

Yes the CDbl/CInt/etc they are also part of VB.NET not just VBA, but probably not the most elegant way to go about this. Maybe also has some side-effects I haven't considered. Type-safety is great but have to get used to it and VBA was quite a loose mistress in this regard ;)

(also miss not having to fully qualify all the enums, like the huge Visio.VisUniqueIDArgs.visGetOrMakeGUIDWithUndo, but alas getting so much back from VS2019 that the VBA IDE does not offer)

How do I make sure the VisUnitCodes setting leads to a double when reading Cell.Result? Thank you for your insights!
« Last Edit: May 02, 2021, 04:37:31 AM by Visisthebest »
Visio 2021 Professional

Visisthebest

  • Sr. Member
  • ****
  • Posts: 376
Re: Type safety in VB.NET and Visio cells
« Reply #1 on: May 02, 2021, 04:36:13 AM »
And for reading double values from Shape Data (also from VB.NET add-in), is this ok:

CDbl(MyShape.Cells("Prop.MyCustomProp").FormulaU)

Or is there a more elegant solution to ensure a double type (in no particular units) is returned?
Visio 2021 Professional

Nikolay

  • Hero Member
  • *****
  • Posts: 1056
    • UnmanagedVisio
Re: Type safety in VB.NET and Visio cells
« Reply #2 on: May 02, 2021, 07:59:56 AM »
There is Cell.ResultIU. Should work for doubles

Visisthebest

  • Sr. Member
  • ****
  • Posts: 376
Re: Type safety in VB.NET and Visio cells
« Reply #3 on: May 02, 2021, 10:24:46 AM »
Thank you Nikolay, life saver you are :) Microsoft has so poorly documented things from the VB.NET perspective everything is from the weakly typed VBA perspective.
Visio 2021 Professional

Visisthebest

  • Sr. Member
  • ****
  • Posts: 376
Re: Type safety in VB.NET and Visio cells
« Reply #4 on: May 02, 2021, 10:29:01 AM »
On a related note, where can one nominate Nikolay for becoming a Microsoft Visio MVP? :D
Visio 2021 Professional

Nikolay

  • Hero Member
  • *****
  • Posts: 1056
    • UnmanagedVisio
Re: Type safety in VB.NET and Visio cells
« Reply #5 on: May 02, 2021, 02:48:37 PM »
Thank you, but I've been expelled already for doing nothing for one and a half year ;D
Looks like I'm just not up to the task of doing something on regular basis, like writing educational/promotional articles or videos, not to speak about conferencing.
I'm more at the level of writing the code for money rather than speaking/doing evangelist things actually.
BTW, there is no such thing as Visio MVP anymore, this nomination has been cancelled a few years ago (replaced by "Office and Services").

Other than that, currently I'm not really doing much for Visio (except supporting/improving my existing solutions of course).
Hopefully, we (me and the company I'm working with now) will put a decent product by summer to the Teams/SharePoint marketplace.
No replacement for Visio Online, but to some extent the drawing functionality will present there (good enough for our goals). It's based on mxgraph, not visio.

Doesn't it look somewhat similar to Visio (this is Teams tab)? Multi-user co-authoring (live), undo/redo are there! Will probably brag about it here as soon as we have it published :D


« Last Edit: May 02, 2021, 03:11:32 PM by Nikolay »

Visisthebest

  • Sr. Member
  • ****
  • Posts: 376
Re: Type safety in VB.NET and Visio cells
« Reply #6 on: May 03, 2021, 01:52:20 AM »
Might I add, you bringing MxGraph/diagrams.net functionality puts your Teams solution way ahead of the functionality of Visio web.

Hopefully this will stimulate Microsoft to up their investment in Visio significantly, both desktop and web, because with this release Microsoft is waaaaaaaaaaaaaaaay behind in web functionality within their own teams platform.

I also understand the Visio import/export is pretty decent.

Competition is a good thing, hopefully this helps the Visio team to get more funding to move Visio development faster than the glacial pace of the past years.
« Last Edit: May 03, 2021, 02:20:22 AM by Visisthebest »
Visio 2021 Professional