PDA

View Full Version : Microsoft VBScript runtime error '800a0009'


esthera
07-31-2006, 09:21 AM
I am doing the following code reading a text file but getting an error
Microsoft VBScript runtime error '800a0009'

Subscript out of range: '[number: 0]'

testa.asp, line 12


can you help?



Set fs=Server.CreateObject("Scripting.FileSystemObject")
Set f=fs.OpenTextFile(sfile, 1)
do while f.AtEndOfStream = false
str=f.readline
arrstr=split(str,",",-1,1)

response.write arrstr(0) & "-" & arrstr(1) & "-" & arrstr(2) & "<br>"

loop
f.Close
set f=Nothing
Set fs=Nothing

Spudhead
07-31-2006, 02:30 PM
Which one is line 12?

If str is empty, or doesn't contain a comma, then arrstr isn't going to be much of an array. I'd test for those conditions before trying to split() str.

esthera
07-31-2006, 02:40 PM
so you think it might be reading in the last line as blank?
I"ll test that out.

glenngv
07-31-2006, 07:29 PM
do while f.AtEndOfStream = false
str=f.readline
arrstr=split(str,",",-1,1)
if ubound(arrstr) <> -1 then
response.write arrstr(0) & "-" & arrstr(1) & "-" & arrstr(2) & "<br>"
end if
loop