Project Help!


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 8 of 8

Thread: Project Help!

  1. #1
    Join Date
    Jan 2007
    Posts
    4

    Project Help!

    Hi! I am new in here and I am also new to VB! I am currently learning VB and I have a project!

    I am having a few problems with my project and I hope you guys can help me!

    I am creating a quiz generator. I want to insert a timer for the submit button. I am using ms access to contain all the questions. The user is supposed to do 20 questions and I want to limit to 30 secs for every qn. I want to insert a timer such that, if the user does not click the submit button within the given time, the next qn should appear.

    Thanks!

  2. #2
    Join Date
    Oct 2005
    Location
    Maady
    Posts
    1,819
    make the timer interval = 30000
    and in the event "yourTimer_Timer()" put your code to navigate to the next question ,
    this event will be acceed every 30000 milliseconds = 30 seconds ...
    you may also need to check if in this interval the user has answered or not to get the results and reset the timer ..
    Programmer&Cracker CS
    MyBlog:Blog.Amahdy.com
    MyWebsite:www.Amahdy.com

  3. #3
    Join Date
    Aug 2004
    Location
    Orange, California
    Posts
    1,261
    If your form is referencing a recordset object that has the questions in it, one for each record, then in your timer event you just need to do a rs.MoveNext and then check the rs.EOF flag so you know when you have finished with the last record/question.

  4. #4
    Join Date
    Jan 2007
    Posts
    4
    I am still not able to get it! Can help me by showing a sample code. Thanks!

  5. #5
    Join Date
    Oct 2005
    Location
    Maady
    Posts
    1,819
    What u can't do ? I mean u need help in timer or in database ?
    What u have tried to do ? u stoped where ? post your try and we will help u update it .
    Programmer&Cracker CS
    MyBlog:Blog.Amahdy.com
    MyWebsite:www.Amahdy.com

  6. #6
    Join Date
    Jan 2007
    Posts
    4
    The following is the original code without the timer.

    Option Explicit On
    Option Strict On

    Imports System.Globalization
    Public Class QuizForm

    Public score As String
    Public qnsAttempted As String
    ' If user does not want to continue the quiz,
    ' a message would pop up to confirm.

    Private Sub endQuizButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles endQuizButton.Click
    Dim button As DialogResult
    button = MessageBox.Show("Are you sure you want to end quiz?", "Quit", _
    MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, _
    MessageBoxDefaultButton.Button2)

    ' If the user clicks yes on the message box,
    ' the particulars form, the instructions form and the quiz form would close.
    ' This would ensure a proper exit of the entire program.

    If button = Windows.Forms.DialogResult.Yes Then
    Me.Visible = False
    ResultsForm.ShowDialog()
    End If
    End Sub

    Private Sub QuizForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    'TODO: This line of code loads data into the 'VbQuizDataSet.Questions' table. You can move, or remove it, as needed.
    Me.QuestionsTableAdapter.Fill(Me.VbQuizDataSet.Questions)

    ' shows the instructions dialog box when quiz form loads.
    InstructionsForm.ShowDialog()

    End Sub
    Private Sub submitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles submitButton.Click

    Dim recPtrPos As Integer
    Dim userAnswer As String = ""
    Static numCorrect As Integer
    Static numIncorrect As Integer
    Dim questionsAttempted As Integer
    Dim randomGenerator As New Random
    Dim randomNumber1 As Integer
    Dim randomNumber2 As Integer
    Dim randomNumber3 As Integer
    Dim randomNumber4 As Integer
    Dim randomNumber5 As Integer
    Dim randomNumber6 As Integer
    Dim randomNumber7 As Integer
    Dim randomNumber8 As Integer
    Dim randomNumber9 As Integer
    Dim randomNumber10 As Integer
    Dim randomNumber11 As Integer
    Dim randomNumber12 As Integer
    Dim randomNumber13 As Integer
    Dim randomNumber14 As Integer
    Dim randomNumber15 As Integer
    Dim randomNumber16 As Integer
    Dim randomNumber17 As Integer
    Dim randomNumber18 As Integer
    Dim randomNumber19 As Integer
    Dim randomNumber20 As Integer

    ' store position of record pointer
    recPtrPos = QuestionsBindingSource.Position

    ' determines selected radio button, which
    ' represents the user's answer
    If optionARadioButton.Checked = True Or optionBRadioButton.Checked = True Or _
    optionCRadioButton.Checked = True Or optionDRadioButton.Checked = True Then
    Select Case True
    Case optionARadioButton.Checked
    userAnswer = optionARadioButton.Text.Replace("&", "")
    Case optionBRadioButton.Checked
    userAnswer = optionBRadioButton.Text.Replace("&", "")
    Case optionCRadioButton.Checked
    userAnswer = optionCRadioButton.Text.Replace("&", "")
    Case optionDRadioButton.Checked
    userAnswer = optionDRadioButton.Text.Replace("&", "")
    End Select
    Else
    MessageBox.Show("Please choose an option!", "Error", MessageBoxButtons.OK, _
    MessageBoxIcon.Exclamation)
    End If

    ' Update number of correct answers
    If userAnswer = _
    VbQuizDataSet.Questions(recPtrPos).Answer Then
    numCorrect = numCorrect + 1
    Else
    numIncorrect = numIncorrect + 1
    End If

    ' Show number of correct answers in score textbox
    score = Convert.ToString(numCorrect)
    scoreTextBox.Text = score

    ' Show number of questions attempted in questions attempted textbox
    questionsAttempted = numCorrect + numIncorrect
    qnsAttempted = Convert.ToString(questionsAttempted)
    questionsAttemptedTextBox.Text = qnsAttempted

    ' generates random numbers which are greater or equal to 0 and lesser than 8
    randomNumber1 = randomGenerator.Next(0, 2)
    randomNumber2 = randomGenerator.Next(2, 4)
    randomNumber3 = randomGenerator.Next(4, 6)
    randomNumber4 = randomGenerator.Next(6, 8)
    randomNumber5 = randomGenerator.Next(8, 10)
    randomNumber6 = randomGenerator.Next(10, 12)
    randomNumber7 = randomGenerator.Next(12, 14)
    randomNumber8 = randomGenerator.Next(14, 16)
    randomNumber9 = randomGenerator.Next(16, 18)
    randomNumber10 = randomGenerator.Next(18, 20)
    randomNumber11 = randomGenerator.Next(20, 22)
    randomNumber12 = randomGenerator.Next(22, 24)
    randomNumber13 = randomGenerator.Next(24, 26)
    randomNumber14 = randomGenerator.Next(26, 28)
    randomNumber15 = randomGenerator.Next(28, 30)
    randomNumber16 = randomGenerator.Next(30, 32)
    randomNumber17 = randomGenerator.Next(32, 34)
    randomNumber18 = randomGenerator.Next(34, 36)
    randomNumber19 = randomGenerator.Next(36, 38)
    randomNumber20 = randomGenerator.Next(38, 40)

    ' chooses the record from the database according to
    ' the random number that is created
    ' after 20 questions have been completed the dialog box appears
    If questionsAttempted = 0 Then
    QuestionsBindingSource.Position = randomNumber1
    ElseIf questionsAttempted = 1 Then
    QuestionsBindingSource.Position = randomNumber2
    ElseIf questionsAttempted = 2 Then
    QuestionsBindingSource.Position = randomNumber3
    ElseIf questionsAttempted = 3 Then
    QuestionsBindingSource.Position = randomNumber4
    ElseIf questionsAttempted = 4 Then
    QuestionsBindingSource.Position = randomNumber5
    ElseIf questionsAttempted = 5 Then
    QuestionsBindingSource.Position = randomNumber6
    ElseIf questionsAttempted = 6 Then
    QuestionsBindingSource.Position = randomNumber7
    ElseIf questionsAttempted = 7 Then
    QuestionsBindingSource.Position = randomNumber8
    ElseIf questionsAttempted = 8 Then
    QuestionsBindingSource.Position = randomNumber9
    ElseIf questionsAttempted = 9 Then
    QuestionsBindingSource.Position = randomNumber10
    ElseIf questionsAttempted = 10 Then
    QuestionsBindingSource.Position = randomNumber11
    ElseIf questionsAttempted = 11 Then
    QuestionsBindingSource.Position = randomNumber12
    ElseIf questionsAttempted = 12 Then
    QuestionsBindingSource.Position = randomNumber13
    ElseIf questionsAttempted = 13 Then
    QuestionsBindingSource.Position = randomNumber14
    ElseIf questionsAttempted = 14 Then
    QuestionsBindingSource.Position = randomNumber15
    ElseIf questionsAttempted = 15 Then
    QuestionsBindingSource.Position = randomNumber16
    ElseIf questionsAttempted = 16 Then
    QuestionsBindingSource.Position = randomNumber17
    ElseIf questionsAttempted = 17 Then
    QuestionsBindingSource.Position = randomNumber18
    ElseIf questionsAttempted = 18 Then
    QuestionsBindingSource.Position = randomNumber19
    ElseIf questionsAttempted = 19 Then
    QuestionsBindingSource.Position = randomNumber20
    ElseIf questionsAttempted = 20 Then
    Me.Visible = False
    ResultsForm.ShowDialog()
    End If

    ' unchecks all radio buttons when moving on to next question
    optionARadioButton.Checked = False
    optionBRadioButton.Checked = False
    optionCRadioButton.Checked = False
    optionDRadioButton.Checked = False

    End Sub
    End Class

    I want to insert the timer such that each qn has a time limit of 30 secs. If the user has not checked any of the radio buttons and click the submit button and there is still time for the qn, an error message must pop up. If the user has not checked any of the radio button and the time is up, the qn should be cosidered as attempted and that qn should also be considered wrong.

    Thanks!

  7. #7
    Join Date
    Oct 2005
    Location
    Maady
    Posts
    1,819
    Ah u r talking about vb.net .. I don't use it frequently but I'll try to tell u the general idea with a simple code example and maybe anyone correct my code if it contains mistakes.
    -first put a new timer control in your form and call it "timer1" say.
    -in the timer1 proprieties choose the interval to be : 30000 (=30 seconds)
    -now in the timer1_timer() event (for the timer1) put a code like this :
    Code:
    if not (optionARadioButton.Checked or optionBRadioButton.Checked or _
    optionCRadioButton.Checked or optionDRadioButton.Checked) then
    MessageBox.Show("Time over for this question !")
    nextques() 'function to go to next ques.
    else
    submitButton_Click()
    end if
    also you need to reset the timer afte the submitbutton has been clicked, I mean in the end of its click() event put this code :
    'it's a traditional method to reset timer:
    timer1=0
    timer1=true
    '-------------------------------------
    to have a better code you can put all the nesseray code for navigate to the next question in an external function nextques() say and call it in the event click for submitbutton and in the previous if condition insteed of repeating the code ... also you can reduce your code using arrays [reduce size and stress].
    Programmer&Cracker CS
    MyBlog:Blog.Amahdy.com
    MyWebsite:www.Amahdy.com

  8. #8
    Join Date
    Jan 2007
    Posts
    4
    Thanks!

    I just started learning arrays and function. I should be able to use ur method once I have shrunk the coding...

Similar Threads

  1. Control Arrays in VB.NET
    By Gary Nelson in forum .NET
    Replies: 277
    Last Post: 10-01-2003, 12:00 AM
  2. Good Editorial by Russell Jones
    By Robert G in forum .NET
    Replies: 84
    Last Post: 02-08-2001, 02:38 PM
  3. Replies: 0
    Last Post: 09-13-2000, 10:18 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center