1 Replies - 2374 Views - Last Post: 11 October 2007 - 05:50 AM Rate Topic: -----

#1 bryanarzaga  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 09-October 07

Need helpp Score Function in Quiz Software

Posted 09 October 2007 - 02:30 PM

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.


	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: 09 October 2007 - 02:32 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Need helpp Score Function in Quiz Software

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1639
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Need helpp Score Function in Quiz Software

Posted 11 October 2007 - 05:50 AM

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
'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

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)

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

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

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 :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1