FIX: GP Faults from Using IIF with Temporary StringsLast reviewed: October 30, 1997Article ID: Q127069 |
3.00
WINDOWS
kbprg kbbuglist
The information in this article applies to:
SYMPTOMSUsing the IIF statement may cause a general protection (GP) fault in a range of addresses from 0023:6BB0 to 0023:7DE0 within VBRUN300.DLL or from 004A:68D0 or 004a:7B00 within VB.EXE. This is a subtle bug that may not be encountered and will not occur on a line using the IIF statement. Other GP faults in segment 23 of VBRUN300.DLL are more indicative of calling a DLL incorrectly, such as forgetting to put "byval" on a DLL's string parameter.
CAUSEThe IIF statement does not release string handles for temporary strings used in its arguments. Under certain conditions, this can result in a GP fault occurring at a seemingly random location later in your program. The code below demonstrates the condition where IIF will not release its string handles.
dim x$ x$ = "World" y$ = "Hello World" Label1.Caption = IIf(3 > 1000, "Hello " & x$, Mid$( y$, 1, 5 ) )The second and third arguments of this statement result in temporary strings being created. This does not, however, cause the GPF. One of two other events must occur for that to happen:
WORKAROUNDAvoid the use of functions that return Strings within the IIF statement. For example, to avoid the bug, modify the code listed in the CAUSE section of this article to this:
dim y$, z$ y$ = "Hello World" z$ = "Small World" Label1.Caption = IIf(3 > 1000, y$, z$ )Here's another alternative:
if 3 > 1000 then label1.caption = y$ else label1.caption = z$ end if STATUSThis bug was corrected in Microsoft Visual Basic version 4.0 for Windows.
|
Additional reference words: 3.00 GPF buglist3.00 fixlist4.00
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |