Microsoft KB Archive/125421

{|
 * width="100%"|

General Protection Fault Using DateValue or TimeValue

 * }

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 for Applications 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.