Volume 3: Programming with the Visio Object Model disclaimer


Getting a Formula or Its Result



Download 0.78 Mb.
Page12/36
Date29.01.2017
Size0.78 Mb.
#11974
1   ...   8   9   10   11   12   13   14   15   ...   36

Getting a Formula or Its Result


Once you have a Cell object, use its Formula property to get its formula as a string.

If you want the formula’s value instead, use one of the Result properties.

Result and ResultIU return a double precision value as a floating-point number with 15 significant digits.

ResultInt returns a long integer.

ResultStr returns the value as a string.

You can specify units for the value returned by a Result property by passing any valid unit string or one of the unit constants defined in the Visio type library.

For example, you can use visDrawingUnits to get a result expressed in units defined for the drawing. To explicitly specify a unit-less number, use visNumber.

Tip:

Use VBA’s Intellisense to help view available Visio constants. In VBA just type “vis”, hold down the Ctrl key and press the space bar. Also check the Developer Reference help file for a complete list of these constants.




Tip:

Visio’s internal units are inches, for cells that measure linear dimensions or radians for cells that measure angular dimensions.



Setting a Formula


When you set formulas from a program, you probably won’t need to construct the kinds of complex formulas you’ve been building in the class to control shape behavior. Those more complex formulas will most likely already be in place in your solution.



Note:

Using the equal sign (=) is optional, just as it is when you type in the ShapeSheet window

To set a cell value to a constant, set either the Result or the Formula.

If you’re working with a cell whose formula is guarded, you’ll need to use the “force” equivalents of Formula and Result:


  • FormulaForce

  • ResultForce

  • ResultIUForce

  • ResultFromIntForce



Tips for Positioning Shapes


Positioning shapes in a drawing can be a challenge, and exactly how you do this will depend on the kind of drawing your program creates. The Drop method requires the position to be in drawing units (not page size). Only when you have an unscaled drawing are these the same.

One simple technique involves calculating the shape’s position relative to the page’s width and height. For example, if you know you want to center a shape on the page, you can drop its pin at (PageWidth*0.5, PageHeight *0.5).

Another technique is to position one shape at a constant offset from another–by getting the PinX and PinY values of one shape and adding the offset to them for the other.


Tips for Positioning Shapes (Continued)


There may be functionality in your solution that requires page size to change based on how many shapes are added or deleted from the page.

Visio provides the ResizeToFitContents method for Master and Page objects. This method resizes the page to fit tightly around the shapes that are on it. This method is the equivalent of clicking the Size to fit drawing contents on the Page Size tab in the Page Setup dialog.

Because the page is resized using this method, the PinX and PinY values in your shapes will typically change. If your solution keeps track of shape position, this fact may ultimately be a deterrent of using the ResizeToFitContents method.



Note:

Using this method, the page extents are right at the edge of the outer most shapes on the page. Consider using a page margin offset and the CenterDrawing method together to enhance shape position on the final page.



Connecting Shapes


To create a connected diagram from a program, you work with cells, but in a slightly different capacity. You are not interested in their formulas or results; instead, you use them to indicate what gets glued to what.

Assume that you are working with two shapes on the drawing, A and B. To connect the shapes:


  • Use the Cells property of shape A to get a Cell object that represents the part of the shape you want to glue, such as a control handle.

  • Use the GlueTo method of that Cell object and indicate a cell that represents the part of shape B you want to glue to, such as a connection point. (You do not necessarily need to get a Cell object for shape B.)

  • Or, use the GlueToPos method of shape A’s Cell object and indicate the shape you want to glue to shape B with a position relative to shape B’s width-height box.



Download 0.78 Mb.

Share with your friends:
1   ...   8   9   10   11   12   13   14   15   ...   36




The database is protected by copyright ©ininet.org 2024
send message

    Main page