Hi guys, I don't know if anyone out there can help me with this. I will start of by explaining exactly what I am doing.

I am currently developing a web based online examination system in ASP.net. Now I have set it up and it works perfectly except for one thing. The test currently asks 9 questions. I have implemented this by using an array. Now if I try to increase the size of the array from 8 to 9 and then compile it, the page never loads. In firefox it just says loading and it doesn't do anything for a long time. But for strange reason, when I make the size of the array anything less than 9, the page loads fine. Is there something I am missing or doing wrong, I have pasted the code of the page below. I would really appreciate it if anyone out there could take a loot at it and let me know where the problem is so I can fix it. Thank you. Please note that the array is the variable named (a) so please just take a look at any where u see it appearing.

Imports System.Web.Security     '   ||||||   Required Class for Authentication
Imports System.Data             '   ||||||   DB Accessing Import
Imports System.Data.SqlClient   '   ||||||   SQL Server Import
Imports System.Configuration    '   ||||||   Required for Web.Config appSettings |||||

Partial Class section1
    Inherits System.Web.UI.Page
    Dim marks As Decimal
    Dim total_questions As Decimal
    Dim score As Decimal
    Dim count As Integer
    Dim ans As String
    Dim a(9), t As Integer
    Dim adp As New SqlDataAdapter
    Dim ds As New DataSet
    Dim ctr As Integer
    'Dim MyConn As SqlConnection = New SqlConnection(System.Configuration.ConfigurationManager.AppSettings("strConn"))
    Dim connStr As String = ConfigurationManager.ConnectionStrings("MainConnStr").ConnectionString
    Dim MyConn As SqlConnection = New SqlConnection(connStr)
    Dim mydate As DateTime
    Dim cmd As New SqlCommand
    Dim dt As New DataTable
    Dim dr As DataRow
    Public userid As String
    Dim ds2 As New DataSet
    Dim adp2 As New Data.SqlClient.SqlDataAdapter
    Dim cmd2 As New SqlCommand
    Dim mydate2 As DateTime = Now
    Dim mydate3 As DateTime
    Dim s1_score As Decimal

    Sub Show()

        dt = Session("Answered")
        Dim v As View = Me.View1

        Dim l As Label
        l = CType(v.FindControl("Label1"), Label)
        l.Text = dt.Rows(ctr).Item("Serial") & "."
        l = CType(v.FindControl("Label2"), Label)
        l.Text = dt.Rows(ctr).Item("question")

        Dim r As RadioButtonList
        r = CType(v.FindControl("RadioButtonList1"), RadioButtonList)
        r.SelectedIndex = dt.Rows(ctr).Item("selected")

        Session("ctr") = ctr
    End Sub

    Protected Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick

            mydate3 = (mydate - mydate2).ToString
            Me.Label5.Text = "Time Left: " & mydate3.ToShortTimeString
        Catch ex As Exception
            Me.Label5.Text = ""
        End Try

        If mydate3.ToShortTimeString = "00:00:00" Then

            Dim marks As Decimal
            dt = Session("Answered")

            For Each x In dt.Rows
                If x("Selected") + 0 = x("correct") Then
                    marks += 1

                End If

        End If
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Session("logged_in") = True And Session("studentID") = "" Then Response.Redirect("login.aspx")

        userid = Request.QueryString("userid")
        Response.Write("userid =" & userid)
        Response.Write("      ")
        'mydate = Request.Cookies("start").Value

        If Not IsPostBack Then
            Me.MultiView1.ActiveViewIndex = 0
            cmd.Connection = MyConn

            Dim arbit As New Random

X:          For i = 0 To a.GetUpperBound(0)
                t = arbit.Next(1, 10)

                If Array.IndexOf(a, t) = -1 Then
                    a(i) = t

                    GoTo X
                End If


            For i = 0 To 9
                cmd.CommandText = "select * from questionsMC where Serial=" & a(i)
                adp.SelectCommand = cmd
                adp.Fill(ds, "questionsMC")


            dt = New DataTable("Answered")
            dt.Columns.Add("Serial", GetType(Integer))
            dt.Columns.Add("question", GetType(String))
            dt.Columns.Add("choice1", GetType(String))
            dt.Columns.Add("choice2", GetType(String))
            dt.Columns.Add("choice3", GetType(String))
            dt.Columns.Add("choice4", GetType(String))
            dt.Columns.Add("correct", GetType(String))
            dt.Columns.Add("selected", GetType(Integer))

            Dim r As DataRow

            For Each r In ds.Tables("questionsMC").Rows
                dr = dt.NewRow
                dr("Serial") = dt.Rows.Count + 1
                dr("question") = r.Item("question")
                dr("choice1") = r.Item("choice1")
                dr("choice2") = r.Item("choice2")
                dr("choice3") = r.Item("choice3")
                dr("choice4") = r.Item("choice4")
                dr("correct") = r.Item("correct")
                dr("selected") = -1


            Session("Answered") = dt

            Call Show()

        End If

    End Sub

    Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click

        ctr = Session("ctr")
        dt = Session("Answered")
        Session("ctr") = ctr
        ctr += 1
        If ctr = 9 Then
            Me.Button2.Enabled = False

        End If
        Me.Button1.Enabled = True
    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

        ctr = Session("ctr")
        dt = Session("Answered")
        ctr = ctr - 1
        If ctr = 0 Then
            Me.Button1.Enabled = False

        End If
        Session("ctr") = ctr
        Me.Button2.Enabled = True

    End Sub

    Protected Sub RadioButtonList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadioButtonList1.SelectedIndexChanged

        dt = Session("Answered")
        For Each drow In dt.Rows
            If drow("Serial") = Me.Label1.Text Then
                drow("Selected") = Me.RadioButtonList1.SelectedIndex
                Exit For

            End If

        Session("Answered") = dt

    End Sub

    Protected Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click

        dt = Session("Answered")

        For Each x In dt.Rows
            If x("Selected") + 1 = x("correct") Then
                marks += 1

                total_questions = 10
                s1_score = marks

                score = FormatNumber((marks / total_questions) * 100, 1)
                'FormatNumber(score, 3)
                'marks = (marks / total_questions) * 100

            End If
        's1_score = marks

        'cmd2.Connection = MyConn
        'cmd2.CommandText = "Insert INTO results Values('07051077')"
        'adp2.SelectCommand = cmd2

        'cmd2.Connection = MyConn
        'cmd2.CommandText = "select [last_name] from [dbo].[users] where [student_id]=" & userid
        'adp2.SelectCommand = cmd2


        'AddTestScore(userid, mydate2, score)

        'Response.Redirect("results.aspx?score=" & score)
        Response.Redirect("section2.aspx?userid=" & userid & "&s1_score=" & s1_score)

    End Sub

End Class

Edited by __avd: Added [code] tags. Encase your code in: [code] and [/code] tags.

7 Years
Discussion Span
Last Post by reach_yousuf

Hello there

I think your problem is array of fixed length.
Dim a(9), i will suggest you couple of things in your code.
1) just change dim a(20) then try
2) in for loop try a.getupperbound or ubound(a)
eg :

for i=0 to ubound(a)-1

instead of

For i = 0 To 9

in your code

loading status in browser is may be because of infinite loop. pls. debug your code to confirm.

Mark as fixed if it helps you!!!

Edited by reach_yousuf: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.