WD: Simulating XOR Logic with Field Codes or WordBasicLast reviewed: February 2, 1998Article ID: Q80510 |
The information in this article applies to:
SUMMARYThis article describes how to simulate the XOR logic in Microsoft Word by using either field codes or the WordBasic macro language. NOTE: Beginning with Word 97, Visual Basic for Applications includes the XOR logical operator.
MORE INFORMATIONTo reproduce the XOR operation in Word for Windows using a WordBasic function, use the following formula
XOR=(Abs(test1 + test2 +... + testn) Mod 2) * - 1for example:
Sub MAIN a =(2 = 2) b =(2 = 3) c =(2 = 3) If XOR(a, b, c) Then Print "XOR is True" Else Print "XOR is False" End If End Sub Function XOR(a, b, c) XOR = (Abs(a + b + c) Mod 2) * - 1 End FunctionThe following is an explanation of how the function works:
{IF {IF x ="T" "T" "F"} = {IF y ="T" "T" "F"} "F" "T"}In the above example, the field on either side of the equal sign (=) checks to see if the comparison is TRUE. If it is, the results are TRUE; if not, the result is FALSE. The comparison of the two IF statements yields TRUE if they are the same and FALSE if they are not. The following table illustrates the values and the results:
Statement 1 Statement 2 Results ----------- ----------- ------- T T F T F T F T T F F FYou can also create this kind of logical structure in a Word for Windows macro. In the following example, T=TRUE and F=FALSE. In WordBasic, the IF statement is combined with the THEN and ELSE statements. An example would be as follows:
IF X$="T" THEN Test1$="T" ELSE Test1$="F" IF Y$="T" THEN Test2$="T" ELSE Test2$="F" IF Test1$=Test2$ THEN Results$="F" ELSE Results$="T" END IFFor more information on the If...Endif statement, search for "WordBasic Programming Language" and "If...ElseIf...Else...End If" using the Help menu.
REFERENCES"Microsoft Word for Windows User's Guide," version 2.0, pages 747-762, 774-776 "Microsoft Excel Function Reference," version 3.0, page 155 "GW-Basic Interpreter User's Guide," page 60
|
Additional query words:
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |