Welcome to Dream.In.Code
Become an Expert!

Join 149,575 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,690 people online right now. Registration is fast and FREE... Join Now!




Need helpp Score Function in Quiz Software

 
Reply to this topicStart new topic

Need helpp Score Function in Quiz Software, Need Help in Score Function

bryanarzaga
9 Oct, 2007 - 01:30 PM
Post #1

New D.I.C Head
*

Joined: 9 Oct, 2007
Posts: 2


My Contributions
I've tried using viewstates but these are not used at the moment im trying to track the questionnumber and score the answers choosen, hope some one can help me. i just need a score function please.


CODE

    txtSystemAnswer.Text = ""
        lblUserName.Text = "John Doe"
        lblExamineeName.Text = "Charlie Brown's A Dummy"

        'Put user code to initialize the page here

        Dim sysAnswer As String
        Dim usAnswer As String

        Dim TrackQuestNum As Integer
        'lblTrackNum.Text = TrackQuestNum 'Assign Tracking num to lblTrackNum

        'Receive PK/Index for WHERE STATEMENT

        'Me.ReceivingIndex = Val(A_form.ReceivedIndex)

        Me.ReceivingIndex = 1 'This holds ForeignKey value!


        'Me.InitializeComponent()
        'Call RadioButton Blanking
        Me.BlankOutRadio()

        Try

            Me.SqlConnection1.Open()
            'Me.SqlSelectCommand1.CommandText = "Select * From TBL_ExamQuestions WHERE ExamID =  ' " & iRecievedIndex & " ' AND QuestionNum = ' " & thispage & " ' ORDER BY QuestionID ASC"
            Me.SqlSelectCommand1.CommandText = "Select * From TBL_ExamQuestions WHERE ExamID =  ' " & ReceivingIndex & " '  ORDER BY QuestionNum ASC"
            '
            Me.DataSet111.Tables("TBL_ExamQuestions").Clear()
            Me.SqlDataAdapter1.SelectCommand = Me.SqlSelectCommand1
            Me.SqlDataAdapter1.Fill(Me.DataSet111, "TBL_ExamQuestions")

            Me.DataSet111.Clear()
            Me.SqlDataAdapter1.Fill(DataSet111)
            Me.lblQuestNo.DataBind()

            Me.TextBox1.DataBind() 'QuestionBox
            Me.lblSystemAnswer.DataBind()
            Me.txtSystemAnswer.DataBind()
            Me.RadioButton1.DataBind()
            Me.RadioButton2.DataBind()
            Me.RadioButton3.DataBind()
            Me.RadioButton4.DataBind()

            Me.CheckRadioButtons()

            theSystemAnswer = Val(lblSystemAnswer.Text)
            theUserAnswer = Val(MyChoice)


            'Save Data on temp ViewStates
            ViewState("CybertronAnswer") = theSystemAnswer 'SysetmAnswer!
            ViewState("OmegatronAnswer") = theUserAnswer   'UserAnswer
            ViewState("TotalQuestion") = intTotalQuestion
            ViewState("Score") = intScore
            ViewState("QuestionNo") = intQuestionNo
            'ViewState("AnswerHistory") = arrAnswerHistory

            Me.txtSystemAnswer.Text = theSystemAnswer

        Catch ex As Exception
            ' No code YET!
        Finally
        End Try




    End Sub


    Public Sub btnNextQuest_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNextQuest.Click
        Dim abc As String
        Dim index As Integer
        Dim TrackQuestNum As Integer
        Dim ThisScore As Integer



        theSystemAnswer = ViewState("CybertronAnswer")
        theUserAnswer = ViewState("OmegatronAnswer")
        intTotalQuestion = ViewState("TotalQuestion")
        intScore = ViewState("Score")
        intQuestionNo = ViewState("QuestionNo")
        'arrAnswerHistory = ViewState("AnswerHistory")

        If theUserAnswer = theUserAnswer Then
            Me.lblUserName.Text = "Something went in!"

            Application.Item("ThisScore") = Application.Item("ThisScore") + ThisScore
            Me.lblYourScore.Text = Application.Item("ThisScore")
        Else

            Me.lblUserName.Text = "Its not equal"
        End If


        Me.ShowNextQuestion(intQuestionNo)  'Load next question!
        Me.BlankOutRadio()     'Call RadioButton Blanking!


    End Sub

    Public Sub ShowNextQuestion(ByVal intQuestionNo As Integer)
        Dim abc As String
        Dim index As Integer
        Dim TrackQuestNum As Integer
        Dim usAnswer As String
        Dim sysAnswer As String



        If theUserAnswer = theUserAnswer Then
            Me.lblUserName.Text = "Something went in!"

            Application.Item("ThisScore") = Application.Item("ThisScore") + thisScore
            Me.lblYourScore.Text = Application.Item("ThisScore")
        Else

            Me.lblUserName.Text = "Its not equal"
        End If


        index = Me.ViewState("index")
        index += 1

        If index > DataSet111.Tables(0).Rows.Count - 1 Then
            index = DataSet111.Tables(0).Rows.Count - 1
            'index = 0
        End If

        Me.ViewState("index") = index  'stores the number to viewstate
        abc = DataSet111.Tables(0).Rows(index).Item("TheQuestion")
        DataView1.Sort = "QuestionNum"
        DataView1.RowFilter = "TheQuestion='" & abc & "'"

        Me.TextBox1.DataBind()
        Me.lblQuestNo.DataBind()
        Me.txtSystemAnswer.DataBind()
        Me.lblSystemAnswer.DataBind()
        Me.RadioButton1.DataBind()
        Me.RadioButton2.DataBind()
        Me.RadioButton3.DataBind()
        Me.RadioButton4.DataBind()

        Do
            ViewState("CybertronAnswer") = theSystemAnswer
            ViewState("TotalQuestion") = intTotalQuestion
            ViewState("Score") = intScore
            ViewState("QuestionNo") = intQuestionNo
        Loop While (ViewState("index") = index)


    End Sub
    Sub CheckRadioButtons()
        'Check Radio Button Inputs!!!!

        '        Me.ViewState("Ans1") = ans1
        '       Me.ViewState("Ans2") = ans2
        If RadioButton1.Checked Then
            Me.lblYourAnswer.Text = "A"
            MyChoice = "A"
        ElseIf RadioButton2.Checked Then
            Me.lblYourAnswer.Text = "B"
            MyChoice = "B"
        ElseIf RadioButton2.Checked Then
            Me.lblYourAnswer.Text = "C"
            MyChoice = "C"
        ElseIf RadioButton2.Checked Then
            Me.lblYourAnswer.Text = "D"
            MyChoice = "D"
        End If

    End Sub
    Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged

        If Page.IsPostBack Then
            MyChoice = "A"
            Me.lblYourAnswer.Text = "A"
            Me.thisUserAnswer = Me.lblYourAnswer.Text

        End If
    End Sub
    Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged
        MyChoice = "B"
        Me.lblYourAnswer.Text = "B"
        Me.thisUserAnswer = Me.lblYourAnswer.Text
    End Sub
    Private Sub RadioButton3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton3.CheckedChanged
        MyChoice = "C"
        Me.lblYourAnswer.Text = "C"
        Me.thisUserAnswer = Me.lblYourAnswer.Text
    End Sub
    Private Sub RadioButton4_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton4.CheckedChanged
        MyChoice = "D"
        Me.lblYourAnswer.Text = "D"
        Me.thisUserAnswer = Me.lblYourAnswer.Text
    End Sub
    Sub BlankOutRadio()
        'Blank-Out the RadioButtons!
        Me.RadioButton1.Checked = False
        Me.RadioButton2.Checked = False
        Me.RadioButton3.Checked = False
        Me.RadioButton4.Checked = False
    End Sub


This post has been edited by bryanarzaga: 9 Oct, 2007 - 01:32 PM
User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: Need Helpp Score Function In Quiz Software
11 Oct, 2007 - 04:50 AM
Post #2

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 9,482



Thanked: 161 times
Dream Kudos: 9050
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
To be honest with you I wouldn't use ViewState for this anyways. I would use an Array and pass it from page to page. On the first page create your 2 dimensional array
CODE

'I initialized it to one for each dimension
'You would want to initialize to how many questions and
'answers you would have for that page
Dim quizArray As Array = Array.CreateInstance(GetType(Integer), 1,1)


Then on each subsequent page, I would use ReDim Preserve to increase the size of the array, like so

CODE

Public Sub ResizeArray(size)
     'Create your new array based on the
     'array passed to the method
     Dim quizArray As Array = _quizArray
     'Resize the array to the size of the current array
     plus the number of elements you want to resize by
     ReDim Preserve quizeArray(array.GetUpperBounds(_quizArray)+size,array.GetUpperBounds(_quizArray)+size)
End Sub


When you resize an array, like we've done above, all data is wiped from the array, and the array is increased by the size you specify. To prevent this we use ReDim Preserve which allows you to resize the array and preserve the data currently in the array.

Now the size attribute we're passing to our method. Lets say on page 1 you have 10 questions, you would initialize your 2 dimensional array to the size of 10 (you see 9 as the size but arrays are 0 index based)

CODE

Dim quizArray As Array = = Array.CreateInstance(GetType(Integer), 9,9)


Then you add your values to it when they complete all the questions and click the next button

CODE

quizArray.Add(question1,answer1)
......
quizeArray.Add(questionN,answerN)

'set the property of the array property you've set on page 2
Page2.quizArray = quizArray
'Say you have 10 questions on the next page
'Pass the number 10 to your procedure
Page2.ResizeArray(10)


Where question1 and answer1 are your values from your quiz. Then on the 2nd page create a public array property

CODE

Dim _quizArray As Array
Public Property quizArray As Array
     Get
           Return _quizArray
     End Get
     Set(value As Array)
           _quizArray = value
     End Set
Ed Property
        


Once you call the ResizeArray method on page 2 it resizes your array while keeping the values from page 1 in it. Do this for every page in your quiz, then when you get to the last page you'll have a 2 dimensional array populated with all your questions/answers.

Hope this helps smile.gif
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 10:31PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month