Printing a Shapes User Defined property

Started by Michael, November 22, 2011, 12:34:30 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Michael

Hi,

I suspect I've got something fundamental missing from my code. I've defined a property in a shape called "Process Owner" (no space  or quotes for the actual name) and have formatted it as text - and indeed I can enter text, say "Conan the Barbarian", and it's stored very nicely.

However, when I try to print this value to a document, I get a big, fat zero (0) and not the actual contents.

I'm using the line of code:

Print #1, "<p>Process Owner: ", Format$(shp.Cells("Prop.ProcessOwner")), "</p>"

On the same print run, another user defined property prints as expected via:

Print #1, "<p>Exported: ", Format(shp.Cells("Prop.ExportDate"), "dddd, mmmm dd, yyyy"), "</p>".

I tried adding , "@" between the two trailing parentheses and also reloving the "$" after "Format", but got the same results.

Am I missing something?

Jumpy

You could try shp.Cells("Prop.ProcessOwner").ResultStr("") to get the value of the property.

Michael

Brilliant! You're a star! Thanks!

Interestingly enough (or not  ;) ) I was also trying to get a bit of VBA to update the same field automatically (I want to change, maybe 500 shapes at once) so tried this line of code:

shp.Cells("Prop.ProcessOwner") = "Conan the Barbarian"

and it returned "Run-time Error 13; Type mismatch", which, with my limited knowledge, seems to indicate that the shape is presenting the property as an integer, even though it's formatted as, and holds, text. Either that, or VBA is expecting an integer.

If push comes to shove, I can use the Sandrilla "Shape substitute" function as a "brute force" solution but it's not ideal (unless, of course, I can convince my clients to buy SuperUtilities for all the users.)

Jumpy

I wonder that

shp.Cells("Prop.ProcessOwner") = something

or

something = shp.Cells("Prop.ProcessOwner")

ever worked for you.


'If you want to get or set a value of any shapesheet cell you can/should/must(?) use:
shp.Cells("Prop.ProcessOwner").Result("mm") 'here I get a value in mm (5 mm -> 5)
shp.Cells("Prop.ProcessOwner").Result("in") 'get the same value in inch (5mm -> X?)
shp.Cells("Prop.ProcessOwner").ResultU("mm") 'see above
shp.Cells("Prop.ProcessOwner").ResultStr("") 'The value as a String
shp.Cells("Prop.ProcessOwner").Formula 'gives you the the formula in the cell
'if in your the formula in your cell is =Width and Width is 5 mm,
' .Result("mm") will return 5 but .Formula will return the String "=Width"!!!
shp.Cells("Prop.ProcessOwner").FormulaU 'gives you the the universel (not localised?) formula in the cell

'When setting values:
shp.Cells("Prop.ProcessOwner").Formula = "Conan" 'is what you want

'and at last the Info that there exists sth. called FormulaForce and ResultForce that
'even let you set values to cells that are protected or guarded.

hth Jumpy





Michael

Thanks, Jumpy.

The codes actually have never worked. I had this same problem when I first wrote the script about 9 months ago but work created an enforced break and so have only just got back to looking at them again.

I added the ".Formula" qualifier to the end of my shp.Cells("Prop.ProcessOwner") = "Conan the Barbarian" and it returned a Run-time error with "#NAME?" at the first shape it encountered. I've tried changing the shapes but the result, so far, is the same.

I've had a look at the ShapeSheet and all the parameters seem correct; also I can enter the text (and delete it) manually in the shape itself. As far as the shape is concerned, it IS a text property - and your previous solution shows it does contain text.

I can comment the code out or hit it with "On Error" but that's not really a solution. I may look into the sth solution, but again, I don't think that's an ideal fix and would wonder if it would be available should somebody run the code on a computer that does not have the SDK installed.

aledlund

as a note from the side, I almost always check to see if a cellexists before attempting to read/write to the cell. A good example of this is the SetCustomPropertyValue method that is in the Visio SDK.
hth,
al

Jumpy

Al has raised a good point there. With first checking if a cell exists you avoid 50% of your troubles.
For your imidiate problem:

shp.Cells("Prop.ProcessOwner").Formula = 5
places the value 5 in the cell, or better changes the formula to =5.

shp.Cells("Prop.ProcessOwner").Formula = "Width"
places the formula =Width in the cell.

You see that in the case of Width the quotes are omitted, because it's a formula.
Same now happens to your string:
shp.Cells("Prop.ProcessOwner").Formula = "Conan the Babarian"
places the formula =Conan the Barbarian in your cell.
And that is a function or a cellname that Visio has never heard of. You could have more luck with "Red Sonja" as Visio knows a function RED but than it will sure as hell need other parameters as Sonja. :D

So you have to tell Visio, that your formula is a string, and that means double quotes which is often done this way:
shp.Cells("Prop.ProcessOwner").Formula = CHR(34) & "Conan the Barbarian" & CHR(34)

hth Jumpy

Michael

Thanks again! It would have taken me much running around in circles to dig out the answer, I suspect.

Al does, indeed, make a good point - I though I had that aspect covered by defining a set of standard shapes (about a dozen), setting the properties & saving them in their own .vss file before I started any work.

That being said, parts of the file date back to 1997 from when I was working in Germany so some oddities may still be lurking...

aledlund

the exposure you run into with custom stencils (and the belief that they will protect you) is that unless your connectors and other attributes (such as controls) also have your key fields, they will fail when your code gets to them. That's the voice of a self inflicted wound. The other thing I try to test for is that when I read what is in a cell that it is not a NULL or Nothing because that often will also fail. That is pretty devastating as well.
hth,
al