General Protection Fault Using DateValue or TimeValue()

Last reviewed: July 29, 1997
Article ID: Q125421
The information in this article applies to:
  • Microsoft Excel for Windows NT, version 5.0
  • Microsoft Excel for Windows, versions 5.0, 5.0c
  • Microsoft Project for Windows, version 4.0
  • Microsoft Visual Basic Programming System, Applications Edition, version 1.0

SYMPTOMS

In Microsoft Excel or Microsoft Project, if you create a Visual Basic, Applications Edition, macro that contains a variable with a type- declaration character (for example "MyVar$"), and you use this variable as an argument in the TimeValue or DateValue functions without assigning a value to it, you may receive a general protection (GP) fault in the file OLE2DISP.DLL when you run the macro. Some of the error messages you may encounter include the following:

  • Microsoft Excel for Windows:

    Excel caused a General Protection Fault in Module OLE2DISP.DLL at 0002:3C2D

  • Microsoft Excel for Windows NT:

          Dr. Watson for Windows NT:
    
             An application error has occurred and an application error
             log is being generated.
             Excel.exe
             Exception access violation (0xc0000005), Address: 0x76eb0b41
    
    
  • Microsoft Project for Windows:

          WinProj4 caused a General Protection Fault in Module OLE2DISP.DLL
          at 0002:4881
    

NOTE: The memory addresses in the above error messages may vary.

CAUSE

The TimeValue or the DateValue function must receive a string data type that is a valid time or date, respectively. If the variable used for the time or date argument has no value, the TimeValue or DateValue function cannot return a valid result.

WORKAROUNDS

Method 1: Use a valid value for the time or date argument.

          For more information about the definition of a valid argument for
          the TimeValue and DateValue functions, see the appropriate topic
          in Visual Basic Reference Help.

Method 2: Check the value of the variable before you use it.

          Use a conditional statement (such as IF) to compare the value of
          the argument to "" (two quotation marks). After this
          verification, use standard error-handling as described in Help.
          For example, you can use the "On Error" statement.

Method 3: Avoid using the string type-declaration character ($).

          Instead of using a variable with a string type-declaration
          character (such as "MyVar$"), use DIM to declare its type, as in
          the following example:

            DIM MyVar as String

          NOTE: A "type-mismatch" error will still occur if you pass this
          variable without assigning a value to it.

STATUS

Microsoft has confirmed this to be a problem in Visual Basic Programming System, Applications Edition. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

REFERENCES

"Visual Basic User's Guide," version 5.0, Chapter 9

For more information, choose the Search button in Visual Basic Reference Help, and type the keyword for the topic you want to view.

   Type this keyword and
   choose Show Topics               Select a topic and choose Go To
   ----------------------------------------------------------------

   errors trapping                  On Error statement
   type-declaration character       type-declaration character <definition>
   TimeValue                        TimeValue
   DateValue                        DateValue


Additional query words: gpf error-handling handling
Keywords : kbcode kbmacro kbprb
Version : 5.00 5.00c | 5.00
Platform : MACINTOSH 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: July 29, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.