Subscript out of range Error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • banning
    New Member
    • Aug 2007
    • 42

    Subscript out of range Error

    Im a PHP developer and I officially HATE ASP

    why does my code give me this error?

    ERROR:
    "Microsoft VBScript runtime error '800a0009'

    Subscript out of range

    /synergy/docs/ProductionRepor ts.asp, line 42 "

    CODE:
    Code:
    	DIM sql: sql = conn.Query("SELECT cmp_name, cmp_code FROM cicmpy")
    	
    	DIM i
    	i=1
    	DO WHILE i<10
    	
    		DIM cmp_name: cmp_name = sql(i)
    		
    		response.write(i & ". " & cmp_name & " - <br /><br />")
    		
    		i=i+1
    		
    	LOOP
  • jhardman
    Recognized Expert Specialist
    • Jan 2007
    • 3405

    #2
    subscript out of range comes up when you have an array that only has 5 elements for example, and you ask for sql(6). A better way to code it would be this, for example:
    Code:
    for each x in sql
       '...
    next
    or
    Code:
    for x = 0 to ubound(sql)
       '...
    next
    Let me know if this helps.

    Jared

    Comment

    Working...