...

View Full Version : Subscript out of range: '[number: 0]'



jimh
02-24-2006, 11:14 PM
Can someone please help me with this error?
***************************************************
Microsoft VBScript runtime error '800a0009'
Subscript out of range: '[number: 0]'

/admin/News.asp, line 73
***************************************************

Here is the code:



<%
Dim oRSNews, strStatusMsg,iNewsID, aResults, oRS
Dim objUpload, strFileName, strPath

'' Instantiate Upload Class
Set objUpload = New clsUpload
Set aResults = Server.CreateObject("Scripting.Dictionary")


If objUpload.Fields("EditID").Value <> "" Then
Dim x
Set oRS = Server.CreateObject("ADODB.Recordset")

iNewsID = objUpload.Fields("EditID").Value
IF NOT IsNumeric(iNewsID) OR iNewsID="" Then
iNewsID = -1
End IF

SQL = "SELECT * FROM tblNews WHERE NewsID = " & iNewsID & ""
oRS.Open SQL, DbObj, adOpenDynamic, adLockOptimistic, adCmdText
Do While Not oRS.EOF
For x = 0 To oRS.Fields.Count - 1
aResults.Add oRS.Fields(x).Name, oRS(x).Value
Next
oRS.MoveNext
Loop

End If

If objUpload.Fields("title").Value <> "" Then

Set oRSNews = Server.CreateObject("ADODB.Recordset")

''Clean Variables
iNewsID = objUpload.Fields("NewsID").Value
IF NOT IsNumeric(iNewsID) OR iNewsID="" Then
iNewsID = -1
End IF

SQL = "SELECT * FROM tblNews WHERE NewsID = " & iNewsID & ""
'SQL = "INSERT INTO tblNews(AuditDate,AuditID,Approved,NewsDate,Title,Highlight ) values('" & _
' Date() & "','1','No','01/01/2004','testtitle2','testhightlight2' )"
'response.write SQL
'DbObj.Execute SQL
oRSNews.Open SQL, DbObj, adOpenDynamic, adLockOptimistic, adCmdText


oRSNews.Addnew
oRSNews.Fields("AuditDate") = Now()
oRSNews.Fields("AuditID") = 1
oRSNews.Fields("Approved") = False
oRSNews.Fields("NewsDate") = objUpload.Fields("newsdate").Value
oRSNews.Fields("Title") = objUpload.Fields("title").Value
oRSNews.Fields("Highlight") = objUpload.Fields("highlight").Value
oRSNews.Fields("PDF") = "PDFFILE"
If Session("sPermUsers") Then
oRSNews.Fields("Approved") = objUpload.Fields("approved").Value
End If

oRSNews.Update

'If objUpload.Fields("pdffile").FilePath <> "" Then

71 ' Grab the file name
72 strFileName = "DKS" & _
73 DatePart("yyyy", objUpload.Fields("newsdate").Value) & _
74 DatePart("m", objUpload.Fields("newsdate").Value) & _
75 DatePart("d", objUpload.Fields("newsdate").Value) & _
"_" & oRSNews.Fields("NewsID").Value & _
"." & StrReverse(Split(StrReverse(objUpload.Fields("pdffile").FilePath), ".", -1, 1)(0))

' Compile path to save file to
strPath = Server.MapPath("/news") & "\" & strFileName

' Save the binary data to the file system
objUpload("pdffile").SaveAs strPath

oRSNews.Fields("PDF") = strFileName
oRSNews.Update
'End If


strStatusMsg = "News Added! " & objUpload.Fields("title").Value
Set objUpload = Nothing
Else
'strStatusMsg = "No Add" '& oRSNews.Status
End If
%>


Any ideas would be greatly appreciated.
Thanks,
Jim

BaldEagle
02-25-2006, 04:57 AM
71 ' Grab the file name
72 strFileName = "DKS" & _
73 DatePart("yyyy", objUpload.Fields("newsdate").Value) & _
74 DatePart("m", objUpload.Fields("newsdate").Value) & _
75 DatePart("d", objUpload.Fields("newsdate").Value) & _
"_" & oRSNews.Fields("NewsID").Value & _
"." & StrReverse(Split(StrReverse(objUpload.Fields("pdffile").FilePath), ".", -1, 1)(0))

I would say the item in red is causing the problem.

BaldEagle

jimh
02-25-2006, 08:40 PM
thanks Bald Eagle, any ideas how I can fix it?

BaldEagle
02-25-2006, 09:20 PM
Why is it there? You do not seem to be accessing an array 'cause all you are doing is building a filename, so I would take it out and see what happens.

BaldEagle

Brandoe85
02-25-2006, 11:14 PM
Why is it there? You do not seem to be accessing an array 'cause all you are doing is building a filename, so I would take it out and see what happens.

BaldEagle

It's their because Split() will return an array of "parts" so if you want to access the first "part" of the split, you can add the index on the end like that.

Just like if you had:


Dim name
name = "jim.johnson"
Response.Write(Split(name, ".")(0))
'writes out jim
Response.Write(Split(name, ".")(1))
'writes out johnson


I would Response.Write(objUpload.Fields("pdffile").FilePath) and see what the value is, if it's empty you will get a subscript error.

Good luck;

BaldEagle
02-25-2006, 11:57 PM
My bad, jimh. Sorry to get you off target. Thanks, Brandoe, I completely missed that.

BaldEagle

GoComplain
02-27-2006, 04:07 AM
Is there anyway that you can Response.Write (value) looking over this code you are Dim'ing everything that I can see pretty good, except "fields"

add fields to your DIM as well (This is my second choice)

Finally I would look in your SUB DATEPART see if there is something in there that is not being DIM'ED

Without more code it is hard to say.

Good luck
Jeff



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum