Software Engineering : This category relates to interesting computer related stuff that I am researching or reading about. Most of it is in the area of .NET technologies which is the focus of most of my computer related time at the moment.
Updated: 9/21/2004; 3:38:01 PM.

 








Subscribe to "Software Engineering" in Radio UserLand.

Click to see the XML version of this web page.

Click here to send an email to the editor of this weblog.

Subscribe To
Mark's Weblog

 
 

Tuesday, June 01, 2004

Creating a Toggle Anchor Lock macro for images in word
Google Search It

I recently wanted a button or keystroke that could automatically toggle the Lock Anchor state for shapes in Microsoft Word.  Unfortunately, there didn't seem to be a built-in Word action for doing this.  Using a tip from Cindy Meister I created the following macro that does the trick nicely:

Sub ToggleShapeAnchor()
    Dim newlockAnchorSetting As Boolean
    If Selection.Type = wdSelectionShape Then
        If (Selection.ShapeRange.Count >= 1) Then
            newlockAnchorSetting = Not Selection.ShapeRange(1).LockAnchor
        End If
        For Each Shape In Selection.ShapeRange
            Shape.LockAnchor = newlockAnchorSetting
        Next
    End If
End Sub

I also had a problem with trying to make fine adjustments of the shapes.  Each adjustment caused the shape to jump a couple inches up the page.  Further adjustment caused it to jump again.  Cindy informed me that this was generally indicative of damage in the binary structures of the control page layout and advised I tried round tripping the file to RTF, WordML, or HTML.  I also found that turning on and off the anchor sometimes seemed to get particular images positioning correctly again.


9:40:54 PM   []    comment []

VS.NET external help didn't work for me until Michael Stokesbary recommended this post from Rob Caron.


9:24:24 PM   []    comment []

The current C# 2.0 specification includes the following quote:

"A comparison operator (==, !=, <, >, <=, >=) has a lifted form when the operand types are both non-nullable value types and the result type is bool. The lifted form of a comparison operator  is formed by adding a ? modifier to each operand type (but not to the result type). Lifted forms of the == and != operators consider two null values equal, and a null value unequal to a non-null value. Lifted forms of the <, >, <=, and >= operators return false if one or both operands are null."

What does this mean?

Perhaps the most significant concept in this paragraphs is at the end where it declares that the operators <= and <= versus the operator == behave differently for Nullable<T> types when that have the value null.  As a result, even though == may return true, the >= operator and the <= operator will sometimes return false.  Let's consider an example.

int? x, y;   // Declares two variables of type Nullable<int>
x = null;
y = null;

Assert.IsTrue(x == y);
Assert.IsFalse(x <= y);

When null is involved with a nullable type, therefore, the >= operator would not be equivalent to the combination of the > and == operators.  In other words,  the expression x>=y would not be equivalent to the combination of x>y || x==y.  Perhaps what is most unusual about this is generally they operator >= is called greater-then-or-equal but in the case of both operands being null, the result of the >= operator would be not equal even though the == operator indicates they are equal.

Furthermore if you were to sort a list of Nullable<T> types using the > operator for ascending order and the < operator for descending order then regardless, all items with the value null would sort to the same location regardless of which operator (< or >) was used (null items would always sort to the top or the bottom regardless of which operator is used.)

Note that currently the May 2005 Visual Studio.NET Tech. Preview does not support the >= and <= operators.  Also, the == operator is marked as obsolete.

I would be curious to know what folks think about this implementation?

(This topic is also being discussed at on the GotDotNet C# Language Message board here.)


4:21:35 PM   []    comment []

© Copyright 2004 Mark Michaelis.



 


June 2004
Sun Mon Tue Wed Thu Fri Sat
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30      
May   Sep


Recent Posts