Subject: Variable Trouble
Posted By: gmoney060 Post Date: 11/1/2004 7:28:10 PM
This is the following code I have:

<%
    'Option Explicit
    ' Set up constants
    Const ForReading = 1 
    Const Create = False

    ' Declare local variables
    Dim objFSO         ' FileSystemObject
    Dim TS             ' TextStreamObject
    Dim strLine        ' local variable to store Line
    Dim strFileName    ' local variable to store fileName

    strFileName = Server.MapPath("/demo/DCI.txt")

    ' Instantiate the FileSystemObject
    Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
    Dim UserData()
    ' use Opentextfile Method to Open the text File
    Set TS = objFSO.OpenTextFile(strFileName, ForReading, Create)

    SectionNumber = 0

    Do While Not TS.AtEndOfStream
        Lines = Replace(Replace(TS.ReadLine,vbTab&vbTab,","),vbTab,",")
        LineComp = Split(Lines,",",-1,1)

        'Section (0) = Version of the DCI Program
        If SectionNumber = 0 Then
            ProgramVersion = LineComp(0)
        End If
        
        'Section(1) = Sanctioing Information
        If SectionNumber = 1 Then
            SanctioningNumber = LineComp(0)
            CordnatorPin = LineComp(1)
            HeadJudgePin = LineComp(2)
        End If
        
        'Section(3) = Players in the tournament
        If SectionNumber = 2 Then
            UserList = UserList & LineComp(1) & "," & LineComp(2) & "," & LineComp(3) & "|"
        End If
        
        If TS.ReadLine = "****" Then
            SectionNumber = SectionNumber + 1
        End If
        
    Loop
%>


Click http://www.topdeckcards.com/demo/dci.txt for the text file I am working with.

The problem is I am like skipping lines almost, and I get the following error on the line blue line about.

Microsoft VBScript runtime error '800a0009'

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

/DCI.asp, line 42

If I dont set it to record LINECOMP(2) or greater it will display:
"1357****" and more stufff. PLEASE HELP


Reply By: rajanikrishna Reply Date: 11/1/2004 8:12:31 PM
Hi,

  Check the ubound(LineComp)

May be it is less than 3. In the line you got error u are showing LineComp(3).

--------
Rajani

Reply By: gmoney060 Reply Date: 11/1/2004 10:30:15 PM
If you look at the txt file i should always have 4 arrays while section number is = 2....

Reply By: mat41 Reply Date: 11/2/2004 3:32:09 AM
A common error, you are referencing an element of the array that does not exist.

Wind is your friend
Matt
Reply By: happygv Reply Date: 11/2/2004 3:35:43 PM
Hi gmoney060,

Your text file looks irregular in case of columns. So it is better you have a check on UBOUND(array) for every line that you read from text file and ensure that you don't go beyond that limit. Else you would end up facing this error, if you use hardcoded values as 1, 2, 3 etc...

Cheers!

_________________________
- Vijay G
Strive for Perfection

Go to topic 21597

Return to index page 726
Return to index page 725
Return to index page 724
Return to index page 723
Return to index page 722
Return to index page 721
Return to index page 720
Return to index page 719
Return to index page 718
Return to index page 717