XL5: Incorrect Use of "Is" Function Causes GP Fault

Last reviewed: September 2, 1997
Article ID: Q112629

The information in this article applies to:

- Microsoft Excel for Windows, version 5.0

SYMPTOMS

In Microsoft Excel version 5.0 for Windows, if you use the Visual Basic for Applications "Is" function incorrectly, you may receive a general protection (GP) fault.

MORE INFORMATION

The "Is" function is used to compare two object reference variables. The result of an Is operation is either TRUE (if the variables both refer to the same object) or FALSE (if they do not).

For example, if you have the following code:

   Set Alpha = ActiveWorkbook.Sheets(1)
   Set Bravo = ActiveWorkbook.Sheets(1)

   Set Charlie = Alpha
   Set Delta = Alpha

All of these commands will return the value TRUE:

   Alpha Is Charlie
   Alpha Is Delta
   Charlie Is Delta

Note that Bravo Is <object>, where <object> is Alpha, Charlie, or Delta, will return FALSE, because the value of Bravo is not the same as the value of Alpha, Charlie, or Delta, even though they both refer to the same object.

If you use the "Is" function to compare a valid object reference (for example, Alpha) to an invalid object reference (for example, a numeric value, a string, or any other item that is not an object), you may receive a GP fault.

To prevent this error from occurring, make sure both items being compared are valid objects.

Visual Basic Code Example

Microsoft provides examples of Visual Basic for Applications procedures for illustration only, without warranty either expressed or implied, including, but not limited to the implied warranties of merchantability and/or fitness for a particular purpose. The Visual Basic procedures in this article are provided 'as is' and Microsoft does not guarantee that they can be used in all situations. While Microsoft support engineers can help explain the functionality of a particular macro, they will not modify these examples to provide added functionality, nor will they help you construct macros to meet your specific needs. If you have limited programming experience, you may want to consult one of the Microsoft Solution Providers. Solution Providers offer a wide range of fee-based services, including creating custom macros. For more information about Microsoft Solution Providers, call Microsoft Customer Information Service at (800) 426-9400.

The following code example illustrates the proper use of the "Is" function.

To run this example, position the cursor in the line that reads "Sub GoodIsSubroutine()" and either press the F5 key or choose Start from the Run menu.

'----------------------------------------------------------------------
Option Explicit

Sub GoodIsSubroutine()

   'Dimension variables.
   Dim Alpha As Variant, Bravo As Variant, Charlie As Variant
   Dim Delta As Variant

   'Create object names.
   Set Alpha = ActiveWorkbook.Sheets(1)
   Set Bravo = ActiveWorkbook.Sheets(1)
   Set Charlie = Alpha
   Set Delta = Alpha

   'These are tests to see if one object Is another object. A message
   'box is displayed if the objects are the same. In this case, only the
   'first three messages will be shown.
   If Alpha Is Charlie Then
      MsgBox "Alpha is Charlie!"
   End If

   If Alpha Is Delta Then
      MsgBox "Alpha is Delta!"
   End If

   If Charlie Is Delta Then
      MsgBox "Charlie is Delta!"
   End If

   If Bravo Is Charlie Then
      MsgBox "Bravo is Charlie!"
   End If

   If Bravo Is Delta Then
      MsgBox "Bravo is Delta!"
   End If

End Sub
'----------------------------------------------------------------------

When you run GoodIsSubroutine, you will be shown three message boxes, one for each of the "Is" functions that succeeds.


Additional query words: 5.00 hang stop responding gpf
Keywords : kbprg PgmOthr
Version : 5.00
Platform : WINDOWS


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: September 2, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.