Type Mismatch Error: ‘UBound’

asp-classicvbscript

I need help with a very annoying issue, that I have been working on since 8 this morning.. I am by no means a pro when it comes to debugging classic asp errors. However, I know enough to figure out what is going on, but not completely sure on how to deal/eradicate with this issue:

Issue: sql query could return nothing which would result in my array being empty, which is giving me the error specified in the title.

Code:

  233  while not rs.eof
  234   varCampArray = split(trim(rs("Notes")) & "", ";")
  235       If ubound(varCampArray) > 0 Then
  236           varCampArray2 = split(varCampArray(0) & "", "=")
  237       End If
  238       if ubound(varCampArray2) > 0 then
  254     wend

lines 239-253 are irrelevant(just calculations based off the array and another query) and just wanted to add the 'wend' statement so noone thinks its not properly coded.

Extra Info:
This is for our custom vb application, and for this particular asp file, the user goes to Report>Daily>Summary, and from there the user selects a certain day to get financial summary for that day. If I run the report for today, it runs and I get figures, if I run it for the 26th of this month, it runs and executes with no errors. If I run it for yesterday(4/27/2016) I get this in the reportViewer in our vb app:
(Microsoft VBScript runtime error '800a000d')

Type mismatch: 'ubound'

/apps/Program14/reports/trans_summary.asp, line 238

I havent tried to fix this yet, as I am unsure as to how to handle this issue. I even looked at the iis log file and its error was 500 0 0 130. Then configured IE to properly show details on the error during runtime. And that is what it spit out, and am currently stuck. Any help would be greatly appreciated. Ive googled and read countless other articles but I am still feeling lost a bit on the issue, and Microsoft is about as helpful as foreign tech support.

Best Answer

When ubound(varCampArray) is not >0, what will varCampArray2 have? It might not be an array. This is why UBound method on varCampArray2 throws the error!

Just check if it is array before using UBound.

while not rs.eof
    varCampArray = split(trim(rs("Notes")) & "", ";")
     If ubound(varCampArray) > 0 Then
           varCampArray2 = split(varCampArray(0) & "", "=")
     End If
     If isArray(varCampArray2) Then
         if ubound(varCampArray2) > 0 then
                'do something here
           end If
      Else
           Msgbox "all these time i thought it was an array!!!"
      End If
 wend

Or simply, You can move the second if within the first if block.

while not rs.eof
    varCampArray = split(trim(rs("Notes")) & "", ";")
     If ubound(varCampArray) > 0 Then
           varCampArray2 = split(varCampArray(0) & "", "=")
           if ubound(varCampArray2) > 0 then
                'do something here
           end If
     End If
 wend
Related Topic