Results 1 to 14 of 14

Thread: Is there a way to add 3 numbers above and 2 numbers below a specific label value?

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    May 2006
    Posts
    2,295

    Is there a way to add 3 numbers above and 2 numbers below a specific label value?

    Hi there folks! I am making a simple adding game for my students. The basic idea is the students are given a question, and below the question is a label array with 6 elements from 0 to 5. The label array is called AnsChoiceLBL(0) to (5). The correct answer for the question is in another label caption called CorrectAnsLBL.caption.

    What I would like to do is have it so one of those AnsChoiceLBL array elements is the correct answer, and the rest of the array elements have other numbers (incorrect answers). Since there are 6 elements total, I would like to have 3 elements to have the next 3 numbers after the correct answer, and 2 numbers below the correct answer.

    So if for example, the CorrectAnsLBL.caption was 5, the AnsChoiceLBL array would have numbers like 3,4,5,6,7,8. The numbers could be all mixed up, but I think that would mean the program would have to randomize which element to store the correct answer.

    Would anyone know how to do that? Thanks a ton!

    Justin

  2. #2
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,632

    Re: Is there a way to add 3 numbers above and 2 numbers below a specific label value?

    Regardless of how you order your answers, your most observant students will (hopefully) recognize after a few problems that the correct answer is always (lowest possible answer provided) + 2

    I would suggest a different approach to providing "in the ballpark" answers if you want to test their ability to determine the proper answer rather than their ability to see patterns.

  3. #3
    PowerPoster
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    2,894

    Re: Is there a way to add 3 numbers above and 2 numbers below a specific label value?

    I didn't create a UI with labels, but here's my attempt at the puzzle:

    Code:
    Sub GenerateRandomNumberRange(ByVal p_CorrectAnswer As Long, optional ByVal p_Before As Long=3, optional ByVal p_After As Long=2)
       Static s_Randomized As Boolean
       
       Dim la_Picked() As Boolean ' Stores whether a number has been randomly picked or not
       Dim l_Pick As Long   ' A randomly picked number
       Dim l_PickedCount As Long  ' How many random numbers have been uniquely picked
       Dim l_Ubound As Long ' Upper bound of our range of numbers from which to randomly pick
       
       If Not s_Randomized Then
          ' Never initialized the random number generator before, so let's do that
          s_Randomized = True
          Randomize
       End If
       
       If p_Before < 0 Or p_After < 0 Then Err.Raise 5
       
       l_Ubound = p_Before + p_After + 1   ' Calculate the max range of our series of numbers
       ReDim la_Picked(1 To l_Ubound)
       
       Do
          l_Pick = Int(Rnd * l_Ubound) + 1 ' Pick a random number
          
          If Not la_Picked(l_Pick) Then ' Check if that number has already been picked
             ' The current random number has not already been picked
             l_PickedCount = l_PickedCount + 1   ' Increase our picked numbers count
             la_Picked(l_Pick) = True   ' Mark the current random number as picked
             
             Debug.Print l_Pick + p_CorrectAnswer - p_Before - 1   ' Print the current randomly picked number
          End If
       Loop While l_PickedCount < l_Ubound ' Loop until all available numbers have been picked.
    End Sub
    If you call GenerateRandomNumberRange(5) it will print a random list of Longs from 2 to 7 to the debug window.

  4. #4
    PowerPoster
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    2,894

    Re: Is there a way to add 3 numbers above and 2 numbers below a specific label value?

    Quote Originally Posted by OptionBase1 View Post
    Regardless of how you order your answers, your most observant students will (hopefully) recognize after a few problems that the correct answer is always (lowest possible answer provided) + 2
    +1 OptionBase1 - I thought of that too, but then thought that that might actually be a good thing in an educational setting (depending on the grade level). Finding students who can figure out patterns like this quickly might be a good way to identify higher level students. I think it also depends on how many questions are given...with just a handful, it would be unlikely that anyone figures out the pattern.

    Overall though I agree with you - if you were trying to ensure that there was no discernible pattern then maybe picking a random number based on the previously randomly chosen number that was not the correct answer would be a good approach?

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    May 2006
    Posts
    2,295

    Re: Is there a way to add 3 numbers above and 2 numbers below a specific label value?

    This is fantastic, thank you, and thank you everyone for your help. This works great, but I just realized I ran into a small issue. Is there a way to have it so no answerchoices go below 0, and if they go below 0, replace them with another higher number? Like if the correct answer was 2, and one of the choices was -1, have the program replace -1 with another number not used in the choices?

    Thanks a ton!

  6. #6
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Is there a way to add 3 numbers above and 2 numbers below a specific label value?

    Quote Originally Posted by Justin M View Post
    Is there a way to have it so no answerchoices go below 0, and if they go below 0, replace them with another higher number? Like if the correct answer was 2, and one of the choices was -1, have the program replace -1 with another number not used in the choices?

    Thanks a ton!
    Just a thought
    Code:
    ...
        If p_Before < 0 Or p_After < 0 Then Err.Raise 5
    
       If p_CorrectAnswer - p_Before < 0 Then
          p_After = p_After + (p_Before - p_CorrectAnswer)
          p_Before = p_CorrectAnswer
       End If
    ...
    And a side note. If the possible answers will always be sequential, is there really an point in randomizing them?
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  7. #7
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Is there a way to add 3 numbers above and 2 numbers below a specific label value?

    After reviewing code given by jpbro, I'd suggest that the randomness should be the p_After or p_Before variables.

    For example. Let's say you want 6 total answers, where one will be correct and the other 5 will not. Also, all these numbers will be sequential. Unless you are going to change the p_Before/p_After variables in each call to the function, a pattern exists. In the sample posted earlier, the answer will always be the lowest value answer + 3 (p_Before), just jumbled up. Exception is only if the no-negative rule applied.

    Edited: Here is what I am suggesting
    Code:
    Sub GenerateRandomNumberRange(ByVal p_CorrectAnswer As Long, Optional p_NrDummyAnswers As Long = 5)
       Static s_Randomized As Boolean
       
       Dim p_Before As Long, p_After As Long
       
       If Not s_Randomized Then
          ' Never initialized the random number generator before, so let's do that
          s_Randomized = True
          Randomize
       End If
       
        p_Before = Int(Rnd * (p_NrDummyAnswers + 1))
        If p_CorrectAnswer > -1 Then
            ' prevent negative values if correct answer is non-negative else allow it
            If p_CorrectAnswer - p_Before < 0 Then p_Before = p_CorrectAnswer
        End If
        p_After = p_NrDummyAnswers - p_Before
        
        For p_After = (p_CorrectAnswer - p_Before) To (p_CorrectAnswer + p_After)
            Debug.Print p_After;
        Next
        Debug.Print
        
    End Sub
    Also note that you are talking only about addition. Similar logic can be used for simple subtraction. But with subtraction and answers can be negative (depending on level of difficulty), changes to the logic should be made to allow negative values even if the correct answer is positive.
    Last edited by LaVolpe; Apr 29th, 2018 at 11:02 AM. Reason: added option when correct answer is a negative value & corrected source to jpbro
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  8. #8
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,632

    Re: Is there a way to add 3 numbers above and 2 numbers below a specific label value?

    Quote Originally Posted by LaVolpe View Post
    And a side note. If the possible answers will always be sequential, is there really an point in randomizing them?
    I didn't post any code, but in response to this question, based on the algorithm requested, if the order of answers wasn't randomized the correct answer would always be C except in situations where (correct answer - 2) was less than 0, which would presumably be infrequently.

  9. #9
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Is there a way to add 3 numbers above and 2 numbers below a specific label value?

    Quote Originally Posted by OptionBase1 View Post
    I didn't post any code
    Ugh, gave credit to the wrong person, Sorry jpbro

    Point taken, but a pattern still existed. Instead of a specific location, answer is a specific offset from the smallest value.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  10. #10
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,632

    Re: Is there a way to add 3 numbers above and 2 numbers below a specific label value?

    Quote Originally Posted by LaVolpe View Post
    Ugh, gave credit to the wrong person, Sorry jpbro

    Point taken, but a pattern still exists. Instead of a specific location, answer is a specific offset from the smallest value.
    Right, which is exactly what I pointed out in my first response to the thread.

    Not knowing what the exact application is, it's impossible to say how important it is, but as I suggested right away, it would be probably best to come up with a different method to generate the "in the ballpark" wrong answers.

    There should even be questions where the correct answer is the lowest number to choose from, and questions where the correct answer is the highest number to choose from. If not, then students will learn to "throw out the lowest and highest answers". This is test writing 101 stuff.

  11. #11
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Is there a way to add 3 numbers above and 2 numbers below a specific label value?

    Quote Originally Posted by OptionBase1 View Post
    There should even be questions where the correct answer is the lowest number to choose from, and questions where the correct answer is the highest number to choose from. If not, then students will learn to "throw out the lowest and highest answers".
    Which I think my suggestion works: randomize the starting point of the sequential numbers. The correct answer can be anywhere in the list, from start to end. If the OP gets into fractions, multiplication & division, then a solution gets a bit more complex to offer reasonable wrong answers along with the correct answer.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  12. #12
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,632

    Re: Is there a way to add 3 numbers above and 2 numbers below a specific label value?

    Quote Originally Posted by LaVolpe View Post
    Which I think my suggestion works: randomize the starting point of the sequential numbers. The correct answer can be anywhere in the list, from start to end. If the OP gets into fractions, multiplication & division, then a solution gets a bit more complex to offer reasonable wrong answers along with the correct answer.
    Yes, that is a much better approach than the original request.

    Again, not knowing anything about the specifics of these questions it is tough to make more suggestions, but if I were writing this myself, I would be tempted to add an "in the ballpark offset" value for each question as well. Say, for example, that a question is written such that the only possible solution is an even number, so then the "in the ballpark" offset could be 2, and then your method on top of that would randomly determine where in the least to greatest range the correct answer fits, but then all other answers are still reasonable since they would all be even numbers.

    You could also add a "always going to be present wrong value" for each question along with a flag that indicates if this value is used or not. If enabled, it ensures that this specific answer will always be listed as an option regardless of the low to high range. This is commonly used when it is easy to misread a question and perform a careless calculation quickly. For example, a diameter is given and the student uses it to calculate area rather than the radius. You would use this value to ensure that the result of d^2*pi is a choice since that is a common mistake made.
    Last edited by OptionBase1; Apr 29th, 2018 at 11:07 AM.

  13. #13
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Is there a way to add 3 numbers above and 2 numbers below a specific label value?

    I've seen posts from this OP before, similar 'quiz-like' topics. He does this for kids. I don't know the level of difficulty he focuses on.

    Edited: Unless I'm getting him confused with another on this forum... Unfortunately, not an uncommon problem now that I'm getting very long in the tooth
    Last edited by LaVolpe; Apr 29th, 2018 at 11:25 AM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  14. #14
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,632

    Re: Is there a way to add 3 numbers above and 2 numbers below a specific label value?

    Fair enough, I wasn't familiar with past threads.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width