Subscript out of Range Error

Discussion in 'C#' started by alexcher, Oct 3, 2007.

  1. #1
    Good day!

    Please help me resolve the problem with regards to Subscript out of Range error I got with my program below:

    __________________________________________________ _

    Function OpenAnswerKey(TypeCode)

    Set rsAnswerKey = Server.CreateObject("ADODB.Recordset")
    sqlAnswerKeyText ="SELECT * FROM tblquestionchoices WHERE TestType = " & "'" & TypeCode & "' " & _
    "ORDER BY QNum;"

    rsAnswerKey.Open sqlAnswerKeyText, objConn

    Do while Not rsAnswerKey.EOF

    Select Case TypeCode
    Case "SCI"
    chrSCIAnswerKey(rsAnswerKey("QNum")) = rsAnswerKey("CorrectAnswer")
    TotalItemSCI = TotalItemSCI + 1
    Case "NUM"
    chrNUMAnswerKey(rsAnswerKey("QNum")) = rsAnswerKey("CorrectAnswer")
    TotalItemNUM = TotalItemNUM + 1
    End Select

    rsAnswerKey.MoveNext
    Loop
    End Function

    __________________________________________________ _

    Actually, I am developing a test questionnaire (60 item-Science category and 40-item Mathematics category). The code above is part of my program for computing the Total Score (combining the raw score of Math and Science).


    The error I got states:

    Error Type:
    Microsoft VBScript runtime (0x800A0009)
    Subscript out of range: 'rsAnswerKey(...)'
    /Technowars/ScoreSummary.asp, line 52


    which pertains to the highlighted part in my code above.


    In addition, please allow me to raise another concern I have.
    The exam is good for only 30 minutes (for the entire Science and Math exam). How can I include such condition in my program? Considering that the exam for Science (SCIENCEQuestionnaire.asp) is separated from the Math (MATHQuestionnaire.asp) exam.


    Please help me resolve this problem. Thank you so much for any help you could offer.


    Best Regards,
    Alexcher
     
    alexcher, Oct 3, 2007 IP
  2. Sellertools

    Sellertools Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Question;

    what is this method: chrNUMAnswerKey. This seems to be the root of the error.
     
    Sellertools, Oct 14, 2007 IP
  3. iShopHQ

    iShopHQ Peon

    Messages:
    644
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    0
    #3
    My guess would be that you aren't passing eough values to the chrSCIAnswerKey function you are calling here:

    chrSCIAnswerKey(rsAnswerKey("QNum"))
     
    iShopHQ, Oct 15, 2007 IP