Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 1st, 2004, 08:28 PM
Authorized User
 
Join Date: Mar 2004
Posts: 84
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to gmoney060 Send a message via MSN to gmoney060
Default Variable Trouble

This is the following code I have:

Code:
<%
    '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


 
Old November 1st, 2004, 09:12 PM
Friend of Wrox
 
Join Date: Sep 2003
Posts: 363
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi,

  Check the ubound(LineComp)

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

--------
Rajani

 
Old November 1st, 2004, 11:30 PM
Authorized User
 
Join Date: Mar 2004
Posts: 84
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to gmoney060 Send a message via MSN to gmoney060
Default

If you look at the txt file i should always have 4 arrays while section number is = 2....

 
Old November 2nd, 2004, 04:32 AM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

A common error, you are referencing an element of the array that does not exist.

Wind is your friend
Matt
 
Old November 2nd, 2004, 04:35 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

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





Similar Threads
Thread Thread Starter Forum Replies Last Post
comapring global variable value to local variable amhicraig XSLT 6 December 5th, 2007 12:16 PM
ASSIGNING A JAVA SCRIPT VARIABLE TO A XSL VARIABLE SOMANATHAN10 XSLT 1 February 21st, 2007 04:26 AM
Object variable or With block variable not set tparrish Classic ASP Databases 0 May 21st, 2005 06:48 AM
Variable trouble tucker Access VBA 0 August 17th, 2004 08:02 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.