WD: Sample Function to Determine If Value Is Odd/Even

Last reviewed: July 30, 1997
Article ID: Q86765
The information in this article applies to:
  • Microsoft Word for Windows, versions 1.0, 1.1, 1.1a, 2.0, 2.0a, 2.0a-CD, 2.0b, 2.0c, 6.0, 6.0a, 6.0c
  • Microsoft Word for Windows 95, versions 7.0, 7.0a
  • Microsoft Word 97 for Windows
  • Word for the Macintosh, versions 6.0, 6.0.1

SUMMARY

The following Microsoft Visual Basic for Applications / WordBasic macro code checks to see if the number 11 is odd or even. You can substitute another number or a numeric variable for the number 11.

   If 11 Mod 2 = 0 Then
       Print "Number is even"
   Else
       Print "Number is odd"
   End If

The MOD operator divides two numbers and returns only the remainder. For example, the result of the expression 19 MOD 7 is 5. The numbers can be any numeric expressions.

REFERENCES

"Using WordBasic," by WexTech Systems and Microsoft, page 227 "Word for Windows and OS/2 Technical Reference", page 191

Kbcategory: kbusage kbmacro KBSubcategory: kbwordvba


Additional query words: 1.0 1.10 1.10a 2.0 2.0a 6.0 6.0.1 7.0
macword winword2 winword word6 word7 word95 word8 word97 8.0 8.0
Version : 2.x 6.0 6.0a 6.0c 7.0 7.0a 9


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: July 30, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.