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 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Apr 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Urgent help needed with Subscript out of range

    I have a form upload script for updating the access database by uploading .csv, and whenever I upload the .csv, I've got an error stating that -

    Microsoft VBScript runtime error '800a0009'

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

    /admin_dates.asp, line 57

    This is my first time dealing with ASP, as I am just editing some other people work. Thanks in advance.
    Following is my source code -

    Code:
    <%
    function SaveFiles
    		Dim uploadsDirVar
    		uploadsDirVar = Server.MapPath("admin")
    
        Dim Upload, fileName, fileSize, ks, i, fileKey
    
        Set Upload = New FreeASPUpload
        Upload.Save(uploadsDirVar)
    
    	' If something fails inside the script, but the exception is handled
    	If Err.Number<>0 then Exit function
    
        SaveFiles = ""
        ks = Upload.UploadedFiles.keys
        if (UBound(ks) <> -1) then
            for each fileKey in Upload.UploadedFiles.keys
                SaveFiles = SaveFiles & Upload.UploadedFiles(fileKey).FileName
            next
        end if
    end function
    
    if Request.ServerVariables("REQUEST_METHOD") = "POST" then
    	uploadFile = SaveFiles()
    		
    	dim fs,f
    	set fs=Server.CreateObject("Scripting.FileSystemObject")
    	set f=fs.OpenTextFile(Server.MapPath("admin/" & uploadFile))
    	f.ReadLine
    	
    	Set datesDataClear = Server.CreateObject("ADODB.Recordset")
    	datesDataClear.ActiveConnection = MM_midas_STRING
    	datesDataClear.Source = "delete * from dates"
    	datesDataClear.CursorType = 0
    	datesDataClear.CursorLocation = 2
    	datesDataClear.LockType = 1
    	datesDataClear.Open()
    	set datesDataClear = Nothing
    
    	Do
    		strAryWords = Split(f.ReadLine, ",")
    		
    		Set datesDataAdd = Server.CreateObject("ADODB.Recordset")
    		datesDataAdd.ActiveConnection = MM_midas_STRING
    		
    		
    		if Ubound(strAryWords) = 7 then
    			sqlString = "insert into dates (schedule, reference, departure, return, nights, status, spaces) values ('" & strAryWords(0) & "','" & strAryWords(1) & "','" & strAryWords(2) & "','" & strAryWords(3) & "','" & strAryWords(4) & "','" & strAryWords(5) & "','" & strAryWords(6) & "')"
    		else
    			sqlString = "insert into dates (schedule, reference, departure, return, nights, status, spaces, comments, othercomments, paxpaying, paxrate, depositdue, depositamt, depositpaid, balancedue, jetski, otheraccom, finalamountdue, finalpaymentdue, finalbalancepaid, accomflightdetails) values ('" & strAryWords(0) & "','" & strAryWords(1) & "','" & strAryWords(2) & "','" & strAryWords(3) & "','" & strAryWords(4) & "','" & strAryWords(5) & "','" & strAryWords(6) & "','" & strAryWords(7) & "','" & strAryWords(8) & "','" & strAryWords(9) & "','" & strAryWords(10) & "','" & strAryWords(11) & "','" & strAryWords(12) & "','" & strAryWords(13) & "','" & strAryWords(14) & "','" & strAryWords(15) & "','" & strAryWords(16) & "','" & strAryWords(17) & "','" & strAryWords(18) & "','" & strAryWords(19) & "','" & strAryWords(20) & "')"
    		end if
    		
    		datesDataAdd.Source = sqlString
    		datesDataAdd.CursorType = 0
    		datesDataAdd.CursorLocation = 2
    		datesDataAdd.LockType = 1
    		datesDataAdd.Open()
    		set datesDataAdd = Nothing
    		
    	Loop Until f.AtEndOfStream
    
    	f.Close
    	set f=Nothing
    	set fs=Nothing
    	
    	response.Redirect("admin_dates.asp")
    
    else
    	Dim datesDataDown
    	
    	Set datesDataDown = Server.CreateObject("ADODB.Recordset")
    	datesDataDown.ActiveConnection = MM_midas_STRING
    	datesDataDown.Source = "SELECT schedule, reference, departure, return, nights, status, spaces, comments, othercomments, paxpaying, paxrate, depositdue, depositamt, depositpaid, balancedue, jetski, otheraccom, finalamountdue, finalpaymentdue, finalbalancepaid, accomflightdetails FROM dates order by id"
    	datesDataDown.CursorType = 0
    	datesDataDown.CursorLocation = 2
    	datesDataDown.LockType = 1
    	datesDataDown.Open()
    	
    	filename = Server.MapPath("admin/" & "schedule.csv")
    	
    	dim fsDown, fDown
    	set fsDown=Server.CreateObject("Scripting.FileSystemObject") 
    	set fDown=fsDown.CreateTextFile(filename,true) 
    	
    	strReturn = "schedule,reference,departure,return,nights,status,spaces,comments,othercomments,paxpaying,paxrate,depositdue,deopsitamt,depositpaid,balancedue,jetski, otheraccom,finalamountdue,finalpaymentdue,finalbalancepaid,accomflightdetails"
    	fDown.WriteLine(strReturn)
    	
    	While NOT datesDataDown.EOF
    		strReturn = datesDataDown.Fields.Item("schedule").Value & "," & datesDataDown.Fields.Item("reference").Value & "," & datesDataDown.Fields.Item("departure").Value & "," & datesDataDown.Fields.Item("return").Value & "," & datesDataDown.Fields.Item("nights").Value & "," & datesDataDown.Fields.Item("status").Value & "," & datesDataDown.Fields.Item("spaces").Value & "," & datesDataDown.Fields.Item("comments").Value & "," & datesDataDown.Fields.Item("othercomments").Value & "," & datesDataDown.Fields.Item("paxpaying").Value & "," & datesDataDown.Fields.Item("paxrate").Value & "," & datesDataDown.Fields.Item("depositdue").Value & "," & datesDataDown.Fields.Item("depositamt").Value & "," & datesDataDown.Fields.Item("depositpaid").Value & "," & datesDataDown.Fields.Item("balancedue").Value & "," & datesDataDown.Fields.Item("jetski").Value & "," & datesDataDown.Fields.Item("otheraccom").Value & "," & datesDataDown.Fields.Item("finalamountdue").Value & "," & datesDataDown.Fields.Item("finalpaymentdue").Value & "," & datesDataDown.Fields.Item("finalbalancepaid").Value & "," & datesDataDown.Fields.Item("accomflightdetails").Value
    		datesDataDown.MoveNext()
    		fDown.WriteLine(strReturn)
    	Wend
    	
    	datesDataDown.Close
    	set datesDataDown = Nothing
    	
    	fDown.Close
    	set fDown=nothing
    	set fsDown=nothing
    	
    end if
    %>

  • #2
    Regular Coder
    Join Date
    Apr 2005
    Location
    Lisbon, CT
    Posts
    339
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Try response.write of your input line before you split it and make sure there are no stray commas. It seems that a line intended for seven items(0-6) is somehow getting by the if statement.

    BaldEagle

  • #3
    New to the CF scene
    Join Date
    Apr 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi,

    I did response.write of the input line and I received 20 and already checked the commas. What should I do next? Thanks

  • #4
    Regular Coder
    Join Date
    Apr 2005
    Location
    Lisbon, CT
    Posts
    339
    Thanks
    0
    Thanked 0 Times in 0 Posts
    By your code you must have two different length lines coming in. Some with seven items and some with 20 items. After looking a bit more closely you should be checking Ubound = 6 not seven. What is happening is that even for lines with seven items it is trying to perform the insert as though it is 20 items because no Ubound = 7 will ever exist.

    BaldEagle


  •  

    Posting Permissions

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