views:

82

answers:

2

Hi, my name is Edd and I need your help. This error occurs on page load in my classic ASP application:

Microsoft VBScript runtime error  '800a0009' 
Subscript out of range: 'cont' 
/admin/cadastros_apz_material.asp, line 173 

The associated code is:

do while not rs.eof
  for i = 1 to tpp
     if i = 1 then matriz(cont) = Rs("id_material_apv_produto") else matriz(cont) = matriz(cont) & "_" & rs("id_material_apv_produto")
     rs.movenext: if rs.eof then exit do
   next: cont = cont + 1
loop: set rs = nothing: if cint(pag) = 1 and ubound(matriz) >= 1 then id = matriz(1)

Thanks.

+2  A: 

It appears that matriz() does not contain an array element at the index whose value is stored in cont.

Guesses:

  • Matriz() is 1-based (Option Base 1, i.e., 1...x) and cont=0
  • Matriz() is too small for the number of records being read
richardtallent
The likelihood of meeting a 1-based array in classic asp is just about zero.
Martha
@Martha: whoops, you're right! There is no "Option Base" in VBScript, only in good ol' VB. Completely forgot about that, haven't touched classic ASP in many years. So, the OP's problem is definitely on the other end of the array.
richardtallent
+3  A: 

First off: The : operator is nice, but you are definitively overdoing it. I recommend cleaning up your code to make it more readable. It helps in debugging too, since it breaks up the line and helps locating the errors by line.

Do While Not rs.EOF
  For i = 1 To tpp
    If i = 1 Then 
      matriz(cont) = rs("id_material_apv_produto") 
    Else 
      matriz(cont) = matriz(cont) & "_" & rs("id_material_apv_produto")
    End If
    rs.MoveNext
    If rs.EOF Then Exit Do
  Next
  cont = cont + 1
Loop
Set rs = Nothing
If CInt(pag) = 1 And UBound(matriz) >= 1 Then 
  id = matriz(1)
End If

Now for your error. It complains that at some point, cont refers to a position outside of matriz. Your array has the wrong dimensions, check how it is created.

Tomalak