General Protection Fault Using DateValue or TimeValue() |
Q125421
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:
Excel caused a General Protection Fault in Module OLE2DISP.DLL at 0002:3C2D
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
WinProj4 caused a General Protection Fault in Module OLE2DISP.DLL at 0002:4881
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.
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 StringNOTE: A "type-mismatch" error will still occur if you pass this variable without assigning a value to it.
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.
"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 :
Issue type :
Technology : kbExcelSearch kbZNotKeyword6 kbExcel500 kbProjectSearch kbVBASearch kbZNotKeyword3 kbExcel500c kbExcel500NT kbProject400 kbVBA100
|
Last Reviewed: January 17, 2001 © 2001 Microsoft Corporation. All rights reserved. Terms of Use. |