Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Feb 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    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
    Last edited by jimh; 02-24-2006 at 11:25 PM.

  • #2
    Regular Coder
    Join Date
    Apr 2005
    Location
    Lisbon, CT
    Posts
    339
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    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

  • #3
    New to the CF scene
    Join Date
    Feb 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks Bald Eagle, any ideas how I can fix it?

  • #4
    Regular Coder
    Join Date
    Apr 2005
    Location
    Lisbon, CT
    Posts
    339
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #5
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    Quote Originally Posted by BaldEagle
    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:
    Code:
    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;

  • #6
    Regular Coder
    Join Date
    Apr 2005
    Location
    Lisbon, CT
    Posts
    339
    Thanks
    0
    Thanked 0 Times in 0 Posts
    My bad, jimh. Sorry to get you off target. Thanks, Brandoe, I completely missed that.

    BaldEagle

  • #7
    New Coder
    Join Date
    Apr 2004
    Location
    Columbus, Ohio
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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
    Hate something?
    Tell us about it
    Go Complain


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •