Iif Function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lee123
    Contributor
    • Feb 2007
    • 556

    Iif Function

    Hi There I've Been Doing Alot Of Projects For My Kids And This Time I Wanted To Do A Math Quiz But I Cant Figure Out How To Use The ("iif") Function For This Project. Lets See If I Can Explain This Right Because Last Time I Had A "formleader " Help Me On The Last Project And He Was Cool Can't Remember His Name But If He Reads This He'll Know Any Way I Have A Form And I Have Three Text Boxes:

    1 - Number1
    2 - Number2
    3 - Useranswer (determins If The User Gets The Answer Right Or Wrong When He Presses Enter)


    And I Have A Button Named "next" ( This Button Generates Random Numbers)


    I Need Someway To Count How Many They Get Right And How Many They Get Wrong Do I Use Two Text Boxes? If So How Can I Use The ("iif") Function In Them To Count This?

    Lee 123
  • vkong85
    New Member
    • Jun 2007
    • 24

    #2
    it seems to me you can just use a query to count how many right and wrong answers ure kids get on the test at the end of the test you can just get simple report off a query and it should just tell them how many right and wrong.

    Comment

    • lee123
      Contributor
      • Feb 2007
      • 556

      #3
      Well I Wanted To Use The "iif" Function In The Control Source Of The Textboxes ( Correct) And ( Incorrect) But Don't Know How To Aproach It. Don't Want A Query I Want Them To See How Many They Get Right And How Many They Get Wrong.on The Form

      Comment

      • lee123
        Contributor
        • Feb 2007
        • 556

        #4
        is there anybody out there who can help!

        Comment

        • FishVal
          Recognized Expert Specialist
          • Jun 2007
          • 2656

          #5
          Originally posted by lee123
          Hi There I've Been Doing Alot Of Projects For My Kids And This Time I Wanted To Do A Math Quiz But I Cant Figure Out How To Use The ("iif") Function For This Project. Lets See If I Can Explain This Right Because Last Time I Had A "formleader " Help Me On The Last Project And He Was Cool Can't Remember His Name But If He Reads This He'll Know Any Way I Have A Form And I Have Three Text Boxes:

          1 - Number1
          2 - Number2
          3 - Useranswer (determins If The User Gets The Answer Right Or Wrong When He Presses Enter)


          And I Have A Button Named "next" ( This Button Generates Random Numbers)


          I Need Someway To Count How Many They Get Right And How Many They Get Wrong Do I Use Two Text Boxes? If So How Can I Use The ("iif") Function In Them To Count This?

          Lee 123
          Hi, Lee.

          Will be glad to help you. Plz clarify the following:
          • what are the purposes of the fields mentioned ?
          • does the answers stored anyway in db table or you simply use correct/incorrect answers counters ?
          • whether the counters should be visible throughout the whole survey or after a kid has answered the last question ?

          Comment

          • lee123
            Contributor
            • Feb 2007
            • 556

            #6
            well the purpose of the fields are when i click on the "next" button it generates random numbers in fields: number1 and number2 then the user or my kids add up the numbers it generates, in a textbox (useranswer) and when they press enter a msgbox pops up and tell them if the number they entered in the textbox (useranswer) is "correct" or if they enter in the wrong number a msgbox pops up and say's "incorrect the correct answer is(whatever the correct answer is) I wanted to use incorrect and correct counters. and i want them visible with a percentage like 80% or 100%

            Comment

            • FishVal
              Recognized Expert Specialist
              • Jun 2007
              • 2656

              #7
              Originally posted by lee123
              well the purpose of the fields are when i click on the "next" button it generates random numbers in fields: number1 and number2 then the user or my kids add up the numbers it generates, in a textbox (useranswer) and when they press enter a msgbox pops up and tell them if the number they entered in the textbox (useranswer) is "correct" or if they enter in the wrong number a msgbox pops up and say's "incorrect the correct answer is(whatever the correct answer is) I wanted to use incorrect and correct counters. and i want them visible with a percentage like 80% or 100%
              You may do it this way.

              Place on the form two additional fields for counters.
              txtRightAnswers Count
              txtWrong AnswersCount
              set their "Format property" to "General Number" and "Visibile" property to "Yes" or "No" on your choice

              Add to code where the answer is resolved to be right or wrong counter incremntig instructions
              [CODE=vb]
              ............... ............... ....
              Me.txtRightAnsw ersCount=Me.txt RightAnswersCou nt+1
              ............... ............... ....
              Me.txtWrong AnswersCount=tx tWrong AnswersCount+1
              ............... ............... ....
              [/CODE]

              For the fields supposed to display right/wrong percentage set "DataSource " property to
              =[txtRightAnswers Count]/([txtRightAnswers Count]+[txtRightAnswers Count])*100
              =[txtWrong AnswersCount]/([txtWrong AnswersCount]+[txtWrong AnswersCount])*100

              Almost as in Excel, just in Access.

              Comment

              • lee123
                Contributor
                • Feb 2007
                • 556

                #8
                THESE CODES I USE :

                Me.txtrightansw erscount = Me.txtrightansw erscount + 1
                Me.txtwrongansw erscount = Me.txtwrongansw erscount + 1

                DO I PUT THEM IN THE CONTROL SOURCE OF THE TWO TXTBOXES I NAMED "CORRECT" AND "INCORRECT" OR BEHIND THE VB CODE WINDOW OF THE USERANSWER.

                I GUESS I EXPLAINED THAT RIGHT...I HOPE

                LEE123

                Comment

                • FishVal
                  Recognized Expert Specialist
                  • Jun 2007
                  • 2656

                  #9
                  Originally posted by lee123
                  THESE CODES I USE :

                  Me.txtrightansw erscount = Me.txtrightansw erscount + 1
                  Me.txtwrongansw erscount = Me.txtwrongansw erscount + 1

                  DO I PUT THEM IN THE CONTROL SOURCE OF THE TWO TXTBOXES I NAMED "CORRECT" AND "INCORRECT" OR BEHIND THE VB CODE WINDOW OF THE USERANSWER.

                  I GUESS I EXPLAINED THAT RIGHT...I HOPE

                  LEE123
                  In VBA code. If you would be so kind to post your code (particulary the part where program logic decides what msgbox to show), I will be more certain in my advices.

                  Comment

                  • lee123
                    Contributor
                    • Feb 2007
                    • 556

                    #10
                    Ok this is what i got in the useranswer txtbox (afterupdate):

                    Dim ANSWER As Integer

                    ANSWER = NUMBER1 + NUMBER2

                    If Val(USERANSWER) = ANSWER Then
                    msgbox "Correct!"
                    Else
                    msgbox "Incorrect! the right answer is: " & ANSWER
                    End If

                    End Sub

                    this is what i got in the button i called "next" (click):


                    Randomize

                    NUMBER1 = Int(Rnd * 10 + 2)
                    NUMBER2 = Int(Rnd * 10 + 2)

                    End Sub



                    the code where the msgboxes are in the afterupdate
                    and the code for the Rnd#'s are in the click event.

                    lee123

                    Comment

                    • FishVal
                      Recognized Expert Specialist
                      • Jun 2007
                      • 2656

                      #11
                      Originally posted by lee123
                      Ok this is what i got in the useranswer txtbox (afterupdate):

                      Dim ANSWER As Integer

                      ANSWER = NUMBER1 + NUMBER2

                      If Val(USERANSWER) = ANSWER Then
                      msgbox "Correct!"
                      Else
                      msgbox "Incorrect! the right answer is: " & ANSWER
                      End If

                      End Sub

                      this is what i got in the button i called "next" (click):


                      Randomize

                      NUMBER1 = Int(Rnd * 10 + 2)
                      NUMBER2 = Int(Rnd * 10 + 2)

                      End Sub



                      the code where the msgboxes are in the afterupdate
                      and the code for the Rnd#'s are in the click event.

                      lee123
                      Place code lines incrementing right/wrong answers counters before (or after, as you like) MsgBox callings.
                      Like this.

                      [CODE=vb]
                      If Val(USERANSWER) = ANSWER Then
                      Me.txtRightAnsw ersCount = Me.txtRightAnsw ersCount + 1
                      msgbox "Correct!"
                      Else
                      Me.txtWrongAnsw ersCount = Me.txtWrongAnsw ersCount + 1
                      msgbox "Incorrect! the right answer is: " & ANSWER
                      End If
                      [/CODE]

                      Comment

                      • lee123
                        Contributor
                        • Feb 2007
                        • 556

                        #12
                        ok i did that and i get a compile error saying that "method or data member not found" i have named the two txtboxes(contro ls) what you told me to name
                        so i don't know why it can't find it. i have also declared your code as a variable

                        as dim txtrightanswers count as integers
                        as dim txtwronganswers count as integers

                        am i suppose to declare it as dim? do you think this is getting frusturating?

                        lee123

                        Comment

                        Working...