[RESOLVED] Stumped -- Compiled executable errors, debug fine.
I can't figure this one out. I get a subscript out of range error in the compiled executable that I'm not getting in the IDE. The error handler that fires is in this routine:
Code:
Private Sub HeaderConfigure()
Dim lWidth As Long, lIndex As Long
On Error GoTo ErrHand
MsgBox "NUM_OFFER_COLS = " & NUM_OFFER_COLS
'Note. If the number of elements in this array changes, NUM_OFFER_COLS should be updated.
With lstOffers
.ListItems.Clear
.ColumnHeaders.Clear
For lIndex = LBound(csColumns) To UBound(csColumns)
If lIndex > NUM_OFFER_COLS Then Exit For
lWidth = goOptions.GetOfferColumns(lIndex)
If lWidth < 0 Then lWidth = DEFAULT_COL_WIDTH
Call .ColumnHeaders.Add(lIndex + 1, , csColumns(lIndex), lWidth)
Next lIndex
End With
ErrHand:
If Err.Number <> 0 Then
Call MsgBox("Error number " & Err.Number & vbCrLf & Err.Description & vbCrLf & _
"in routine HeaderConfigure of OfferTray", vbExclamation, "TrialTrack Error")
End If
End Sub
The function uses a form level array (csColumns) to create column headers for a listview control, and sets the widths from a user options object. The problem apparently doesn't lie in the widths, as when I comment out that line I get the same result. Interestingly, the message box that I stuck in to try and track the problem down is never displayed. I also tried removing the error handler and compiling it, and it did exactly the same thing. Any ideas?
Re: Stumped -- Compiled executable errors, debug fine.
Some questions
1. Is LBound(csColumns) always zero? If not, don't believe you can .Add beyond header count+1
2. in goOptions class, do you have error handling in the GetOfferColumns routine? If so, that could explain why the msgbox is not fired as expected.
3. in goOptions, does GetOfferColumns use an array also? Could the error be happening in there?
Why it is happening compiled vs IDE is interesting, but probably not that important at this point.
Re: Stumped -- Compiled executable errors, debug fine.
Quote:
Originally Posted by LaVolpe
Some questions
1. Is LBound(csColumns) always zero? If not, don't believe you can .Add beyond header count+1
2. in goOptions class, do you have error handling in the GetOfferColumns routine? If so, that could explain why the msgbox is not fired as expected.
3. in goOptions, does GetOfferColumns use an array also? Could the error be happening in there?
Why it is happening compiled vs IDE is interesting, but probably not that important at this point.
1.) csColumns is created by splitting a string in the form's initialize event, so it would always have a 0 LBound. I use the same code in a different form as well, and that one works perfectly.
Code:
Private Sub Form_Initialize()
On Error GoTo ErrHand
If Not geDevMode Then
Call SetIcon(Me.hWnd, INTRAY_ICON, False)
End If
csColumns = Split("Trial Number,Client Name,Offer Date,Offer Type,Underwriter,Broker", ",")
ErrHand:
If Err.Number <> 0 Then
Call MsgBox("Error number " & Err.Number & vbCrLf & Err.Description & vbCrLf & _
"in routine Form_Initialize of OfferTray", vbExclamation, "TrialTrack Error")
End If
End Sub
2-3.) The options class has an error handler (probably doesn't need one as it's a trivial function):
Code:
Public Function GetOfferColumns(lColumn As Long) As Long
On Error GoTo ErrHand
If lColumn <= UBound(clOfferColWidth) Then
GetOfferColumns = clOfferColWidth(lColumn)
End If
ErrHand:
If Err.Number <> 0 Then
csError = vbCrLf & "Error number " & Err.Number & vbCrLf & Err.Description
Err.Clear
Call Err.Raise(vbObjectError, "UserOptions", "UserOptions GetOfferColumns failed." & csError)
End If
End Function
I know that the clOfferColWidth array is being filled and written properly, because the registry setting is created correctly when the program starts and it returns correctly from other places in the code. I alse get the same behavior when that line of code is removed as well.
What is strange is that the error seems to happen before any arrays are accessed.
[EDIT] BTW the first thing I tried was compiling with all of the optimization flags turned off, same result.
Re: Stumped -- Compiled executable errors, debug fine.
Freaky :confused:. This resolved itself when I changed the variable name from lIndex to lColumn. I double checked that lIndex is never used higher than procedure level scope (it wasn't). Looks like a compiler aliasing error. Thanks LaVolpe.
Re: [RESOLVED] Stumped -- Compiled executable errors, debug fine.
This is going to sound like a weird question. In your classes, do you have any that return DOUBLE vartypes, either as arrays or non-arrays? This is beginning to sound like a situation I had once.
Edited: Ignore that last question then. I wonder if you asked for class parameter byval if the error would have also gone away; but don't fix it if it ain't broke.