bugs >> Bug - EXE different to IDE

by Tony Proctor » Sun, 07 Oct 2007 02:47:34 GMT

I don't need a solution to this issue folks. I just want to share something
I've found that might be useful one day...

I recently had an EXE that was crashing with error 9 ("Subscript out of
range"), but worked perfectly well in the IDE. I used the VC++ debugger to
pin it down to the code generated for a 'With' block when referencing an
element of an array of UDTs. In the EXE, the array is examined before the
index expression is evaluated. Hence, if the index expression involves a
function call that populates the array then it crashes. In the IDE, the
index expression appears to be evaluated first and so it works OK.

To put this in perspective, here's a very cut-down example. The iLookup()
function lookups up a date+description in the UDT array. If it's not found
then it creates a new entry. In all cases, it returns the index of the
relevant array entry. When the Form_Load is invoked, the 'With
tArray(iLookup(...))' call is suppose to add the associated date+description
arguments to the array, and then print them out. However, tArray has is not
initialised and does not have a SafeArray description associated with it
before the index expression (i.e. the iLookup call) is evaluated. The EXE
therefore fails while the IDE works.

Tony Proctor

'============= Form1 ================
Private Type Item
dDate As Date
sDesc As String
End Type

Private bInit As Boolean
Private tArray() As Item

Private Function iLookup(dDate As Date, sDesc As String)
If bInit Then
For iLookup = LBound(tArray) To UBound(tArray)
' Check if we've already got this date
If tArray(iLookup).dDate = dDate Then Exit For
Next iLookup
If iLookup > UBound(tArray) Then
' Need to add new date
ReDim Preserve tArray(0 To iLookup)
tArray(iLookup).dDate = dDate
tArray(iLookup).sDesc = sDesc
End If
Else
' Add very 1st date
ReDim tArray(0)
iLookup = 0
tArray(iLookup).dDate = dDate
tArray(iLookup).sDesc = sDesc
bInit = True
End If
End Function

Private Sub Form_Load()
With tArray(iLookup(Date, "Today"))
MsgBox .dDate & " " & .sDesc
End With
End Sub

'==================================




bugs >> Bug - EXE different to IDE

by Ken Halter » Sun, 07 Oct 2007 10:05:27 GMT






fwiw, it works when compiled to PCode.

--
Ken Halter - MS-MVP-VB - Please keep all discussions in the groups..
In Loving Memory - http://www.vbsight.com/Remembrance.htm





bugs >> Bug - EXE different to IDE

by Ralph » Sun, 07 Oct 2007 11:19:13 GMT




message

something

That's because code "running" in the IDE is PCode.

-ralph




Similar Threads

1. dialog form size different in IDE or exe - Visual Basic/VB

2. Bug in IDE?

3. Exception Behaviour Different in IDE - VB.Net

4. IDE step through bug

Hello,

I have found that when stepping through a piece of code the IDE does not 
work correctly.  Here is the code snip:

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As 
System.EventArgs) Handles Button1.Click
        Dim intTest As Int16

        If True Then
            If False Then intTest = 2
        Else
        End If

        MessageBox.Show(intTest.ToString())
    End Sub


To demonstrate the bug, put a break point on the line that says: 

If True Then

Then step through the code.  If you see what I see, then it will appear 
as though the code steps into the assignment intTest = 2.  Thankfuly the 
code is actually working correctly, because as you can see the value of 
intTest has not been changed.  So this is just and IDE step through bug. 

I have only tested this in VB.NET.

I am using: 
Microsoft Development Environment 2003  	Version 7.1.3088
Microsoft .NET Framework 1.1		Version 1.1.4322
Microsoft Visual Basic .NET   69586-335-0000007-18792


I am assuming I am not the only one who has found this bug, but thought 
I should report it anyway.  

Are there any pathes for this?



Thanks

Randy

5. vb.net 2005 bug in the ide (wipes out code) - VB.Net

6. Is VB 2005 Express IDE Full Of Bugs?

I don't know if anyone else is have issues with VB 2005 Express, but we
are, on multiple machines, it crashes during compiles, we have to do
'clean solution' almost very other time we compile.

The IDE hangs all the time.  This happens on clean builds of XP SP2,
existing XP workstations, and even our Test 2003 Server.

Is anyone else having these issues?  At this point, I have recommended
to management we return to VS IDE 2003, at least with it, we know what
the quirks are.

7. How to crash the IDE/Compiler in 5 lines of code (BUG) - VB.Net

8. Bug outside IDE only in Release mode