Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old September 26th, 2005, 06:13 PM
SevenEleven SevenEleven is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 111 SevenEleven User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 4 h 41 m 32 sec
Reputation Power: 5
Parsing Problem

Hi,
I have used this script in the past on a different page with no problems. I have tried to modify it to work with a different page. I am able to get it to create a good .csv file, however I cant get it to write to my DB. I get the following error

Quote:
Microsoft VBScript runtime error '800a0009'

Subscript out of range: 'intRST'


Here is the code - with the error line (118) in bold.

Code:

<% @Language="VBScript" %>
<%
'***
'*  1)  Download NHL statistics via XMLHTTP.
'*  2)  Optionally, write the page to a .TXT file.
'*  3)  Parse the statistics into an array.
'*  4)  Optionally, write the array to a .CSV file.
'*  5)  Update a database table from the array.
'***
   '*
   '*  Declare Constants
   '*
    Const cASP = "NHLStats.asp"
    Const cTXT = "NHLStats.txt"
    Const cCSV = "NHLStats.csv"
    Const cMDB = "dbfiles\NHLPOOL.mdb"
    Const cTBL = "NHLStats"
    Const cDSN = "DRIVER=Microsoft Access Driver (*.mdb);DBQ="
    Const cCOL = "Pos,Player,Team,GP,G,A,PTS,+/-,PPG,SHG,GWG,GTG,PIM,SH,PCT"
    Const cURL = "http://www.tsn.ca/nhl/Statistics.asp?category=Total_Points&position=&division=&season=2004&type=skater&endRow=1170&startRow=1"
    Const cOUT = True  '= Write .TXT and .CSV output files (True/False)
    Const cDBG = True  '= Debugging via "Response.Write()" (True/False)
   '*
   '*  Declare Globals
   '*
    Dim arrRST(499,18)
    Dim intRST
        intRST = 0
    Dim strXML
   '*
   '*  Processing
   '*
    Call Retrieve()
    Call Database()

Sub Retrieve()
   '*
   '*  Declare Variables
   '*
    Dim arrCOL(15)
    Dim intCOL
    Dim strCOL
    Dim strMSG
    Dim strREC
    Dim strVAL
    Dim strVAR
   '*
   '*  Declare Objects
   '*
    Dim objFSO
    Dim objGFI
    Dim objOTF
    Dim objXML
   '*
   '*  Retrieve Web Page
   '*
   'Set objXML = Server.CreateObject("MSXML2.ServerXMLHTTP")
    Set objXML = Server.CreateObject("Microsoft.XMLHTTP")
        objXML.Open "GET", cURL, false
        objXML.Send
        strXML = objXML.ResponseText
    Set objXML = Nothing
   '*
   '*  Optionally Write Files
   '*
    If cOUT Then
        Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
       '*
       '*  Write Web Page to File
       '*
        Set objOTF = objFSO.OpenTextFile(Server.MapPath(cTXT),2,true)
            objOTF.Write(strXML)
        Set objOTF = Nothing
       '*
       '*  Write Web Data to File
       '*
        Set objOTF = objFSO.OpenTextFile(Server.MapPath(cCSV),2,true)
            objOTF.WriteLine(cCOL)
    End If
   '*
   '*  Write CSV File from File
   '*
   '*
        strVAR = Mid(strXML, InStr(strXML, "bgcolor=""#F7EDE0""")-32, Len(strXML))
        strVAR = Left(strVAR, InStr(strVAR, "</table>")-1)
    Do While InStr(strVAR, "<tr") > 0
       '* Now extract the 'record' from the table (like above code)
        strREC = Mid(strVAR, InStr(strVAR, ">")+1)
        strREC = Left(strREC, InStr(strREC, "</tr>")-1)
       '* Now we should be left with all the <td>'s
        intCOL = 0
        Do while InStr(strREC, "<td") > 0
            strVAL = Mid(strREC, InStr(strREC, ">")+1)
            strVAL = Left(strVAL, InStr(strVAL, "</td>")-1)
           '* We have successfully got a value from a <td>!
           '* Maybe at this point you could load it into an array:
            arrCOL(intCOL) = strVAL
           '* Now we have to clean the strREC string up
            strREC = MID(strREC, InStr(strREC, "</td>")+5)
            intCOL = intCOL + 1
        Loop
       '* At this point we have a loaded arrCOL with all the values from the record!
       '* You could build an SQL string at this point or anything really
        strCOL = Join(arrCOL,",")
        strCOL = Replace(strCOL,vbCrLf,"")
       '* Remove hyperlink around Player and Team
        strCOL = Left(strCOL,InStr(strCOL,"<")-1) & Mid(strCOL,InStr(strCOL,">")+1)
        strCOL = Replace(strCOL,"</a>","")
       '* Remove spaces between Player and Team
        Do Until InStr(strCOL,", ") = 0
            strCOL = Replace(strCOL,", ",",")
        Loop
       '* Write Player's data to file
        If cOUT Then objOTF.WriteLine(strCOL)
       '* Write Player's data to array
        intRST = intRST + 1
        arrRST(intRST,0) = strCOL
       '* Now we have to trim up the main string
        strVAR = MID(strVAR, InStr(strVAR, "</tr>")+5)
    Loop
   '*
   '*  Destroy Objects
   '*
    If cOUT Then
        Set objOTF = Nothing
        Set objFSO = Nothing
    End If
End Sub

Sub Database()
   '*
   '*  Declare ADO Constants
   '*
    Const adCmdTable = &H0002
    Const adLockOptimistic = 3
    Const adOpenKeySet = 1
   '*
   '*  Declare Variables
   '*
    Dim intFOR
    Dim strNOW
        strNOW = Now()
    Dim strRST
        strRST = Split(cCOL,",")
    Dim strXDV
    Dim strXTV
   '*
   '*  Extract " as of " Date and Time
   '*
        strXDV = Mid(strXML,InStr(strXML," as of ")+Len(" as of "))
        strXDV = Left(strXDV,InStr(strXDV,"<")-1)
        strXTV = Mid(strXDV,InStr(strXDV,", at ")+Len(", at "))
        strXTV = Replace(strXTV," ET","")
        strXDV = Left(strXDV,InStr(strXDV,", at ")-1)
        strNOW = FormatDateTime(DateValue(strXDV)+TimeValue(strXTV)  ,0)
   '*
   '*  Prepare Array
   '*
    If intRST = 0 Then
        Response.Write "<b>Missing Stats!</b>"
        Exit Sub
    End If
    If cDBG Then Response.Write("<br>0. " & cCOL)
    If UBound(strRST) <> UBound(arrRST,2) Then
        Response.Write "<b>Invalid 'cCOL'!</b>"
        Exit Sub
    End If
    For intRST = 0 To UBound(arrRST,2)
        arrRST(0,intRST) = strRST(intRST)
    Next
   '*
   '*  Declare Objects
   '*
    Dim objADO
    Set objADO = Server.CreateObject("ADODB.Connection")
		objADO.Open cDSN & Server.MapPath(cMDB)
    Dim objRST
    Set objRST = objADO.Execute("DELETE FROM " & cTBL)
    Set objRST = Server.CreateObject("ADODB.Recordset")
        objRST.Open cTBL, objADO, adOpenKeySet, adLockOptimistic, adCmdTable
   '*
   '*  Update Database
   '*
    For intFOR = 1 To UBound(arrRST,1)
        If arrRST(intFOR,0) <> "" Then
            If cDBG Then Response.Write("<br>" & intFOR & ". " & arrRST(intFOR,0))
            strRST = Split(arrRST(intFOR,0),",")
            For intRST = 0 To UBound(arrRST,2)
                arrRST(intFOR,intRST) = strRST(intRST)
            Next
            objRST.AddNew
            objRST("ID") = intFOR
            For intRST = 0 To UBound(arrRST,2)
                objRST(arrRST(0,intRST)) = arrRST(intFOR,intRST)
            Next
            objRST("AsOf") = strNOW
            objRST.Update
        End If
    Next
   '*
   '*  Destroy Objects
   '*
        objRST.Close
    Set objRST = Nothing
    Set objADO = Nothing
End Sub
%>


Thanks for looking.

Reply With Quote
  #2  
Old September 27th, 2005, 04:38 PM
Leslie's Avatar
Leslie Leslie is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Location: Honolulu
Posts: 184 Leslie User rank is Corporal (100 - 500 Reputation Level)Leslie User rank is Corporal (100 - 500 Reputation Level)Leslie User rank is Corporal (100 - 500 Reputation Level)Leslie User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 20 h 29 m 2 sec
Reputation Power: 9
Out of range means that you are trying to put an item in an array that is greater than the upper bound.

You said your first dimension of your array arrRST can only be 499 and no greater. I'm guessing you are trying to place a 500th item in there ... it doesn't mean there is anything wrong with the variable or value in intRST, it means that this statement ...

Do While InStr(strVAR, "<tr") > 0

occurs more than 499 times ... at least that's what I see without totally evaluating your code ...

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingVisual Basic Programming > Parsing Problem


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT