Results 1 to 36 of 36

Thread: Check box and random number

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2008
    Posts
    15

    Check box and random number

    Dear supporters,

    I am just a beginner of VB6 but I know there are plenty of you here in this forum to support people like me.

    I wanted to write a code so that when I click on a command button it shows a random number in the text box. The random number I want will depen on 3 check boxes.

    If the first check box is checked, I want the random number from 1 to 3. If the second check box is checked, I want the random number from 4 to 6. And if the third check box is checked, I want the random number from 7 to 9.

    Then how can I write a code so that when the first and the third check boxes are checked a random number shows in my text box varies either 1, 2, 3, 7, 8 and 9 (but not 4, 5 and 6)?

    Thanks in advance for your help.

    With my best regards,
    Viratha

  2. #2
    Frenzied Member Jmacp's Avatar
    Join Date
    Jul 2003
    Location
    UK
    Posts
    1,959

    Re: Check box and random number

    Use a checkbox control array and then use "select case". And google for the random number generator.

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Check box and random number

    Welcome to the forums.

    What will the random number be if I check all three checkboxes?

    Perhaps the use of option buttons, in this case, would be better.

  4. #4
    PowerPoster Ellis Dee's Avatar
    Join Date
    Mar 2007
    Location
    New England
    Posts
    3,530

    Re: Check box and random number

    There's some complexity to your problem, which makes it interesting. Here's a fully functional solution:
    Code:
    Option Explicit
        
    Private mlngArray() As Long
    Private mlngRange As Long
    
    Private Sub Form_Load()
        Randomize
    End Sub
    
    Private Sub Command1_Click()
        Dim lngNumber As Long
        Dim i As Long
        
        Me.txtDisplay.Text = vbNullString
        ReDim mlngArray(0)
        mlngRange = -1
        For i = 0 To 2
            If Me.chkRange(i).Value = vbChecked Then AddNumbers i
        Next
        If mlngRange = -1 Then
            MsgBox "Check at least one checkbox", vbInformation, "Notice"
        Else
            lngNumber = Int((mlngRange + 1) * Rnd)
            Me.txtDisplay.Text = mlngArray(lngNumber)
        End If
    End Sub
    
    Private Sub AddNumbers(plngIndex As Long)
        Dim i As Long
        
        mlngRange = mlngRange + 3
        ReDim Preserve mlngArray(mlngRange)
        For i = 0 To 2
            mlngArray(mlngRange - 2 + i) = plngIndex * 3 + i + 1
        Next
    End Sub
    Let me know if you have any questions.
    Last edited by Ellis Dee; Dec 18th, 2008 at 07:58 AM.

  5. #5
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    Re: Check box and random number

    Here is the way I would do it. Again you should use a control array of checkboxes to make things easy
    Code:
    Private Sub Command1_Click()
    Dim i As Integer
    Dim strNumString As String
    Dim strNums() As String
    
        'see which checkboxes are checked and
        'add the possible numbers to a string
        For i = 0 To 2
            If Check1(i).Value = vbChecked Then
                strNumString = strNumString & Check1(i).Tag
            End If
        Next i
            
        'Spliting the number string on the space will
        'add all the possiblities to an array
        strNums = Split(strNumString, " ")
        
        'Select a random index from the array
        Randomize
        i = Int(Rnd() * (UBound(strNums)))
        
        'display the results
        Text1.Text = strNums(i)
      
    End Sub
    
    Private Sub Form_Load()
        'add the values for each checkbox
        'note the trailing space is important
        Check1(0).Tag = "1 2 3 "
        Check1(1).Tag = "4 5 6 "
        Check1(2).Tag = "7 8 9 "
        
        Check1(0).Caption = "1-3"
        Check1(1).Caption = "4-6"
        Check1(2).Caption = "7-9"
    End Sub

  6. #6

    Thread Starter
    New Member
    Join Date
    Dec 2008
    Posts
    15

    Re: Check box and random number

    Dear all valued supporters,

    I am very surprised to get in my office early in the morning and found some replies to my thread just posted 12 hours ago (just over night). Many thanks to Jmacp, Hack, Ellis Dec and MarkT for their kind and quick support.

    Although I haven't tried any of these yet but I am sure they are very helpfull. I will try it and let you know the result.

    Thanks again for all supporters.
    All the best to you all,
    Viratha

  7. #7

    Thread Starter
    New Member
    Join Date
    Dec 2008
    Posts
    15

    Re: Check box and random number

    Dear supporters,

    I am very pleased to let you know that my problem is now solved! I've tried MarkT's code and it work perfectly for me. Thanksssss to MarkT.

    All the best,
    Viratha

  8. #8

    Thread Starter
    New Member
    Join Date
    Dec 2008
    Posts
    15

    Re: Check box and random number

    Dear MarkT,

    Your code worked perfectly for me. Thank you very much for your support.

    Best regards,
    Viratha

    Quote Originally Posted by MarkT
    Here is the way I would do it. Again you should use a control array of checkboxes to make things easy
    Code:
    Private Sub Command1_Click()
    Dim i As Integer
    Dim strNumString As String
    Dim strNums() As String
    
        'see which checkboxes are checked and
        'add the possible numbers to a string
        For i = 0 To 2
            If Check1(i).Value = vbChecked Then
                strNumString = strNumString & Check1(i).Tag
            End If
        Next i
            
        'Spliting the number string on the space will
        'add all the possiblities to an array
        strNums = Split(strNumString, " ")
        
        'Select a random index from the array
        Randomize
        i = Int(Rnd() * (UBound(strNums)))
        
        'display the results
        Text1.Text = strNums(i)
      
    End Sub
    
    Private Sub Form_Load()
        'add the values for each checkbox
        'note the trailing space is important
        Check1(0).Tag = "1 2 3 "
        Check1(1).Tag = "4 5 6 "
        Check1(2).Tag = "7 8 9 "
        
        Check1(0).Caption = "1-3"
        Check1(1).Caption = "4-6"
        Check1(2).Caption = "7-9"
    End Sub

  9. #9
    PowerPoster Ellis Dee's Avatar
    Join Date
    Mar 2007
    Location
    New England
    Posts
    3,530

    Re: Check box and random number

    Mark's code will never pick the highest number. To correct this bug, change this line:

    i = Int(Rnd() * (UBound(strNums)))

    To this:

    i = Int((UBound(strNums) + 1) * Rnd)

    EDIT: On second look, the above is not true. His array has an extra unused element, and that's the one that never gets selected. Nice and elegant, Mark.

    To repeat, do not make this change.

    EDIT 2: You shouldn't call Randomize each time. It would be better in the Form_Load event.
    Last edited by Ellis Dee; Dec 19th, 2008 at 12:36 AM.

  10. #10

    Thread Starter
    New Member
    Join Date
    Dec 2008
    Posts
    15

    Re: Check box and random number

    Dear Ellis Dee,

    Many thanks for your mail.

    What do you mean that Mark's code will never pick the highest number?
    I am also having difficulty understanding the rest of your instruction. That because I am new to VB. Sorry

    I attached the form which I developed base on Mark's code for the example. Please have a quick look at that and advise.

    By the way there is an imorvement require for this form. If the command button is clicked while no checkbox is checked there is an error message.
    It read "Run-time eror '9'. Subscription out of range". I want to get rid of this and want a message to tell users to at least check one checkbox.

    Hope you could help.
    Thanks,
    Viratha

    Quote Originally Posted by Ellis Dee
    Mark's code will never pick the highest number. To correct this bug, change this line:

    i = Int(Rnd() * (UBound(strNums)))

    To this:

    i = Int((UBound(strNums) + 1) * Rnd)

    EDIT: On second look, the above is not true. His array has an extra unused element, and that's the one that never gets selected. Nice and elegant, Mark.

    To repeat, do not make this change.

    EDIT 2: You shouldn't call Randomize each time. It would be better in the Form_Load event.
    Attached Files Attached Files

  11. #11
    PowerPoster Ellis Dee's Avatar
    Join Date
    Mar 2007
    Location
    New England
    Posts
    3,530

    Re: Check box and random number

    I clarified that there wasn't a problem about picking the highest number.

    Immediately after the For...Next loop add the following block:
    Code:
        For i = 0 To 2
            If Check1(i).Value = vbChecked Then
                strNumString = strNumString & Check1(i).Tag
            End If
        Next i
            
        If Len(strNumString) = 0 Then
            MsgBox "Check at least one checkbox", vbInformation, "Notice"
            Exit Sub
        End If
            
        'Spliting the number string on the space will

  12. #12
    PowerPoster Code Doc's Avatar
    Join Date
    Mar 2007
    Location
    Omaha, Nebraska
    Posts
    2,354

    Re: Check box and random number

    Build a form with a text box, a command button, and an array of three check boxes (indexed 0 to 2). Then apply this code:

    Code:
    Private Sub Command1_Click()
    Dim MaxVal As Integer, MinVal As Integer
    Text1.Text = vbNullString
    MinVal = 1
    For I = 0 To 2
        MaxVal = MaxVal + 3
        Check1(I).Caption = MinVal & " to " & MaxVal
        If Check1(I).Value = vbChecked Then
            Text1.Text = Text1.Text & Int((MaxVal - MinVal + 1) * Rnd + MinVal)
        End If
        MinVal = MinVal + 3
    Next
    End Sub
    
    Private Sub Form_Load()
    Randomize
    Command1.Value = True
    End Sub
    Doctor Ed

  13. #13

    Thread Starter
    New Member
    Join Date
    Dec 2008
    Posts
    15

    Re: Check box and random number

    Dear Ellis Dee,

    Great! thanks...my second problem (error mesage) solved.

    Best regards,
    Viratha

  14. #14

    Thread Starter
    New Member
    Join Date
    Dec 2008
    Posts
    15

    Re: Check box and random number

    Dear Code Doc,

    Many thanks for your support. Now Mark's and Ellis Dee's codes worked perfectly for me. However, I will try yours one day.

    Best regards,
    Viratha

  15. #15
    PowerPoster Ellis Dee's Avatar
    Join Date
    Mar 2007
    Location
    New England
    Posts
    3,530

    Re: Check box and random number

    Doc, he needs the result to be a single digit number within any of the checked ranges. Note the example from the OP, where if the first and last are checked, the set of possible numbers is 1,2,3,7,8,9.

  16. #16
    PowerPoster Code Doc's Avatar
    Join Date
    Mar 2007
    Location
    Omaha, Nebraska
    Posts
    2,354

    Re: Check box and random number

    Quote Originally Posted by Ellis Dee
    Doc, he needs the result to be a single digit number within any of the checked ranges. Note the example from the OP, where if the first and last are checked, the set of possible numbers is 1,2,3,7,8,9.
    Thanks, Ellis. He wants just one number to appear in the text box, so I revised the code by adding a line after the loop:
    Code:
    Private Sub Command1_Click()
    Dim MaxVal As Integer, MinVal As Integer
    Text1.Text = vbNullString
    MinVal = 1
    For I = 0 To 2
        MaxVal = MaxVal + 3
        Check1(I).Caption = MinVal & " to " & MaxVal
        If Check1(I).Value = vbChecked Then
            Text1.Text = Text1.Text & Int((MaxVal - MinVal + 1) * Rnd + MinVal)
        End If
        MinVal = MinVal + 3
    Next
    If Len(Text1.Text) Then Text1.Text = Mid$(Text1.Text, Int(Rnd * (Len(Text1.Text)) + 1), 1)
    End Sub
    
    Private Sub Form_Load()
    Randomize
    Command1.Value = True
    End Sub
    Mine is a bit different approach. All I did was select one random digit from the elements of the sets of those permitted by the check box constraints.
    Doctor Ed

  17. #17

    Thread Starter
    New Member
    Join Date
    Dec 2008
    Posts
    15

    Re: Check box and random number

    Dear Mark,

    As I told you in my previous message your code worked perfectly for me.
    But now when I want the first checkbox random number range from say 1 to 100 or even bigger, how can I make a short cut instead of "Check1(0).Tag = "1 2 3 4 5 6 7 8 9 10...100..." ?

    Thanks in advance for your kind support.
    Viratha

  18. #18
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    Re: Check box and random number

    You could try something like this
    Code:
    Private Sub Form_Load()
    Dim i as Integer
    
        'add the values for each checkbox
        'note the trailing space is important
        For i = 1 to 100
            ' 1 to 100
            Check1(0).Tag = Check1(0).Tag & i & " "
            ' 101 to 200
            Check1(0).Tag = Check1(0).Tag & i + 100 & " "
            ' 201 to 300
            Check1(0).Tag = Check1(0).Tag & i + 200 & " "
        Next i
    End Sub

  19. #19
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: Check box and random number

    Just poking my nose in .....

    I think I'd take a different approach and create 3 random numbers right at the start, one for each CheckBox range, then randomly select one of them depending upon the combination of selected CheckBoxes.

    Something like this:
    Code:
    Option Explicit
    
    Private intNumbers(2) As Integer
    Private intRanges(2, 1) As Integer
    Private intTemp(2) As Integer
    
    Private Function CreateRandom(intMin As Integer, intMax As Integer) As Integer
    CreateRandom = Int((intMax - intMin + 1) * Rnd + intMin)
    End Function
    
    Private Sub CmdCreate_Click()
    Dim intI As Integer
    Dim intJ As Integer
    '
    ' Create 3 Random Numbers in the appropriate ranges
    '
    For intI = 0 To 2
        intNumbers(intI) = CreateRandom(intRanges(intI, 0), intRanges(intI, 1))
    Next intI
    For intI = 0 To 2
        '
        ' If the CheckBox is selected then copy its Random number
        ' into the next free element of the temporary array
        '
        If Check1(intI).Value = 1 Then
            intTemp(intJ) = intNumbers(intI)
            intJ = intJ + 1
        End If
    Next intI
    If intJ <> 0 Then
        '
        ' Randomly select one of the temporary array elements
        ' and assign it to the TextBox
        '
        txtResult.Text = intTemp(CreateRandom(0, intJ - 1))
    Else
        MsgBox "Please select one of the CheckBoxes"
    End If
    End Sub
    
    Private Sub Form_Load()
    Randomize
    intRanges(0, 0) = 1     'Minimun for CheckBox(0)
    intRanges(0, 1) = 3     'Maximum for CheckBox(0)
    intRanges(1, 0) = 4     'Minimum for CheckBox(1)
    intRanges(1, 1) = 6     'Maximum for CheckBox(1)
    intRanges(2, 0) = 7     'Minimum for CheckBox(2)
    intRanges(2, 1) = 10    'Maximum for CheckBox(2)
    End Sub

  20. #20
    PowerPoster Ellis Dee's Avatar
    Join Date
    Mar 2007
    Location
    New England
    Posts
    3,530

    Re: Check box and random number

    That's probably fine, Doogle, but it will be biased if the checkboxes define different size ranges. For example:

    1 to 3
    4 to 100
    101 to 1001

    1 through 3 will get selected far more than any other numbers. Then again, this may be desired behavior.

  21. #21
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: Check box and random number

    Souped up version - there's no need for the temporary array....
    Code:
    Option Explicit
    
    Private intNumbers(2) As Integer
    Private intRanges(2, 1) As Integer
    
    Private Function CreateRandom(intMin As Integer, intMax As Integer) As Integer
    CreateRandom = Int((intMax - intMin + 1) * Rnd + intMin)
    End Function
    
    Private Sub CmdCreate_Click()
    Dim intI As Integer
    Dim intJ As Integer
    '
    ' If the CheckBox element is selected
    ' create a Random Number in the appropriate range
    ' and assign it to the next free intNumbers element
    '
    For intI = 0 To 2
        If Check1(intI).Value = 1 Then
            intNumbers(intJ) = CreateRandom(intRanges(intI, 0), intRanges(intI, 1))
            intJ = intJ + 1
        End If
    Next intI
    If intJ <> 0 Then
        '
        ' Randomly select one of the array elements
        ' and assign it to the TextBox
        '
        txtResult.Text = intNumbers(CreateRandom(0, intJ - 1))
    Else
        MsgBox "Please select one of the CheckBoxes"
    End If
    End Sub
    
    Private Sub Form_Load()
    Randomize
    intRanges(0, 0) = 1     'Minimun for CheckBox(0)
    intRanges(0, 1) = 3     'Maximum for CheckBox(0)
    intRanges(1, 0) = 4     'Minimum for CheckBox(1)
    intRanges(1, 1) = 6     'Maximum for CheckBox(1)
    intRanges(2, 0) = 7     'Minimum for CheckBox(2)
    intRanges(2, 1) = 10    'Maximum for CheckBox(2)
    End Sub

  22. #22
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: Check box and random number

    Ellis - you're absolutely correct. The skew is very significant, probably too much so to be of much use! (Unless, as you say, that's the intention. ie there's an equal probability of selecting a number from any of the selected CheckBoxes)

    On a trial of 1000 runs using your ranges, 330 were between 1 and 3 when all 3 CheckBoxes were selected (fancy that - nearly a third - goes to show the Random Number Geneator is fairly Random )
    Last edited by Doogle; Dec 21st, 2008 at 01:44 AM.

  23. #23
    PowerPoster Code Doc's Avatar
    Join Date
    Mar 2007
    Location
    Omaha, Nebraska
    Posts
    2,354

    Re: Check box and random number

    Quote Originally Posted by Viratha
    Dear Mark,

    As I told you in my previous message your code worked perfectly for me.
    But now when I want the first checkbox random number range from say 1 to 100 or even bigger, how can I make a short cut instead of "Check1(0).Tag = "1 2 3 4 5 6 7 8 9 10...100..." ?

    Thanks in advance for your kind support.
    Viratha
    Before you change the constraint on the first check box, you need to define what you want the other two check boxes to do as well. How do the second and third check boxes influence the first and vice versa?

    Methinks you are leading the VB6 forum into a snake pit.
    Doctor Ed

  24. #24

    Thread Starter
    New Member
    Join Date
    Dec 2008
    Posts
    15

    Re: Check box and random number

    Mark, thanks for your kind support and quick response. I've tried a bit on your code but sorry it doesn't seem to work the way I want this time.

    (1) if I followed exactly your code, check the first checkbox is ok but check the second and third checkbox will induce a message "Check at least one checkbox".

    (2) I then changed the number in the parenthesis like below:

    For i = 1 to 100
    ' 1 to 100
    Check1(0).Tag = Check1(0).Tag & i & " "
    ' 101 to 200
    Check1(1).Tag = Check1(1).Tag & i + 100 & " "
    ' 201 to 300
    Check1(2).Tag = Check1(2).Tag & i + 200 & " "
    Next i

    After I changed these it seems to work ok.

    I am very sorry for all the inconvenients so far for you and for the forum. In fact I should have given you the whole picture of what I want to do from the beginning. Instead I've invented a simple question with a hope that it be easier understood and to received a simple answer. Then I will work on my own base on the supported codes I got from the forum. However, thing is not as simple as I thought...on the one hand a final product that I want kept changing over time as thing progress...on the other hand the more I've learnt about VB the more complicated interface I want it to be. But isn't it a sign of progress as the result of your support and others in this forum?

    Thanks again to all.
    Viratha

  25. #25
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    Re: Check box and random number

    For #2 that is the danger of copy and paste. Glad to see you got it.

  26. #26
    Frenzied Member
    Join Date
    Jun 2006
    Posts
    1,098

    Re: Check box and random number

    I was just passing by when this thread caught my interest. Of all the solutions, I like mine best

    (This is for you, Ellis Dee. I trust you can figure it out.)
    Code:
    Option Explicit
    
    Private Type Range
      Min As Long
      Max As Long
    End Type
    
    Private AllRanges(2) As Range
    
    Private Sub Form_Load()
      Dim i As Long
      
      Randomize
      
      AllRanges(0).Min = 1
      AllRanges(0).Max = 3
      AllRanges(1).Min = 4
      AllRanges(1).Max = 6
      AllRanges(2).Min = 7
      AllRanges(2).Max = 9
      
      For i = 0 To 2
        Check1(i).Caption = AllRanges(i).Min & " to " & AllRanges(i).Max
      Next i
    End Sub
    
    Private Sub Command1_Click()
      Dim n As Long
      Dim i As Long
      Dim r As Long
      Dim x As Long
      
      For i = 0 To 2
        If Check1(i).Value = vbChecked Then
          n = n + 1 + AllRanges(i).Max - AllRanges(i).Min
        End If
      Next i
      
      If n <> 0 Then
        r = Int(Rnd * n)
        For i = 0 To 2
          If Check1(i).Value = vbChecked Then
            If AllRanges(i).Min + r > AllRanges(i).Max Then
              r = r - 1 - AllRanges(i).Max + AllRanges(i).Min
            Else
              x = AllRanges(i).Min + r
              Exit For
            End If
          End If
        Next i
        Label1.Caption = x
      Else
        Label1.Caption = "-"
      End If
    End Sub

  27. #27
    PowerPoster Ellis Dee's Avatar
    Join Date
    Mar 2007
    Location
    New England
    Posts
    3,530

    Re: Check box and random number

    Quote Originally Posted by Logophobic
    I was just passing by when this thread caught my interest. Of all the solutions, I like mine best

    (This is for you, Ellis Dee. I trust you can figure it out.)
    Yes, it is far and away the best solution. Any size ranges are supported, and it requires no wasted memory on an array holding each possible result. Very nice.

    Though it would have been nice to stuff the Min,Max values in the Tag property of each checkbox to make it easier for the programmer to maintain.

  28. #28

    Thread Starter
    New Member
    Join Date
    Dec 2008
    Posts
    15

    Re: Check box and random number

    Dear Mark,

    Your code bellow as I have informed you worked perfectly for me when I use checkbox with random number.

    Now that I want to change from "checkbox" to "option"…I’ve created an array of option and replaced the word ‘Check1’ with ‘Option1’ in your code…but unfortunately this doesn’t work. I don’t know why but perhaps a required code for checkbox and option in this case is not the same. Would you please advise. Viratha


    Quote Originally Posted by MarkT
    Here is the way I would do it. Again you should use a control array of checkboxes to make things easy
    Code:
    Private Sub Command1_Click()
    Dim i As Integer
    Dim strNumString As String
    Dim strNums() As String
    
        'see which checkboxes are checked and
        'add the possible numbers to a string
        For i = 0 To 2
            If Check1(i).Value = vbChecked Then
                strNumString = strNumString & Check1(i).Tag
            End If
        Next i
            
        'Spliting the number string on the space will
        'add all the possiblities to an array
        strNums = Split(strNumString, " ")
        
        'Select a random index from the array
        Randomize
        i = Int(Rnd() * (UBound(strNums)))
        
        'display the results
        Text1.Text = strNums(i)
      
    End Sub
    
    Private Sub Form_Load()
        'add the values for each checkbox
        'note the trailing space is important
        Check1(0).Tag = "1 2 3 "
        Check1(1).Tag = "4 5 6 "
        Check1(2).Tag = "7 8 9 "
        
        Check1(0).Caption = "1-3"
        Check1(1).Caption = "4-6"
        Check1(2).Caption = "7-9"
    End Sub

  29. #29
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: Check box and random number

    Just change,

    If Check1(i).Value = vbChecked Then

    to

    If Option1(i).Value = True Then

  30. #30

    Thread Starter
    New Member
    Join Date
    Dec 2008
    Posts
    15

    Re: Check box and random number

    Edgemeal, many thanks for your advice. It worked! That is simple but very important for me. Great!
    Last edited by Viratha; Jan 4th, 2009 at 07:59 PM.

  31. #31

    Thread Starter
    New Member
    Join Date
    Dec 2008
    Posts
    15

    Re: Check box and random number

    Dear all, with supports from this forum I am now able to achieve what I wanted. Thanks to Mark for the random number code, to Ellis for the message box code and to Edgemeal for the changing from checkbox to option code. Wow, what a great support. I can’t imagine that I can do this that fast.

    Now I want to improve a product I have achieved. Again need your support (please refer to the attached form).

    If user ticks on anyone of the option in the ‘Subject’ frame the corresponding comboBox will appear bellow the subject frame showing all lessons under that subject. Let say user ticked on 'Geography' subject, lessons in the comboBox are 'Lesson_Geo All, Lesson_Geo 1 and Lesson_Geo n'. In this case (example) only 2 questions (Q4 and Q5) for Lesson_Geo 1 and 1 question (Q6) for Lesson_Geo n.

    After the command ‘Question’ is clicked, what should be a code for:

    1. I want random Q4 or Q5 in the ‘Question’ frame if ‘Lesson_Geo 1’ was selected.
    2. I want Q6 in the ‘Question’ frame if ‘Lesson_Geo n’ was selected.
    3. I want random Q4, Q5 or Q6 in the ‘Question’ frame if ‘Lesson_Geo All’ was selected.
    4. I want all random questions from Q1 to Q12 under all subjects in the ‘Question’ frame if ‘All Subjects’ in the subject frame is selected.
    5. As you would note in the ‘File menu’ there is a ‘Print record’ submenu. What should be a code to print all questions and answers that appear from the start of the interface till the ‘Print record’ is selected?
    6. Apart from the above questions, as a programmer, I want to know how often each question appears as a result of the command ‘Question’ clicked. One way to control this is to record the question codes. How can I code this and view it whenever I want?
    7. Last but not least, what should be a code to control the same random number from being appeared more than once? Forget this question if it is too complicated.

    By the way please note that a random number in the attached form link only with subject in the 'subject' frame but not with lesson in the comboBox.

    Thanks in advance for your kind support. Viratha

    Edit 1: Sorry, question 4 should read "I want all random questions from Q1 to Q12 under all subjects in the ‘Subject’ frame if ‘All Subjects’ in the subject frame is selected."
    Attached Files Attached Files
    Last edited by Viratha; Jan 5th, 2009 at 05:28 AM.

  32. #32

    Thread Starter
    New Member
    Join Date
    Dec 2008
    Posts
    15

    Re: Check box and random number

    Dear all,

    I understand that the questions I posted on 5 January is a bit annoying...too long. Therefore, I should make it short and simpler this time.

    Would anyone please tell me how to write a code so that a range of random number (example 1 to 10) be displayed in the text box when its corresponding item is selected from a comboBox (please refer to the form posted on 5 Jan).

    Thanks in advance.
    Viratha

  33. #33

    Thread Starter
    New Member
    Join Date
    Dec 2008
    Posts
    15

    Re: Check box and random number

    Just want to thank for your help by not helping me. Because you didn't help, I have helped myself. Viratha
    Attached Files Attached Files

  34. #34
    PowerPoster Code Doc's Avatar
    Join Date
    Mar 2007
    Location
    Omaha, Nebraska
    Posts
    2,354

    Re: Check box and random number

    Quote Originally Posted by Viratha
    Just want to thank for your help by not helping me. Because you didn't help, I have helped myself. Viratha
    Lots of people offered their help on this thread. That's absurd.
    Doctor Ed

  35. #35
    Frenzied Member
    Join Date
    Jun 2006
    Posts
    1,098

    Re: Check box and random number

    See post #31. Previous replies were helpful and were appreciated. Viratha's comment in post #33 was likely referring to the lack of further support regarding the additional requests made in post #31.

  36. #36

    Thread Starter
    New Member
    Join Date
    Dec 2008
    Posts
    15

    Re: Check box and random number

    I am very sorry to see some people upset to my comment post #33.

    In fact my thank in post #33 was real and sincere thank. Don’t look at it in a negative way.

    Even when I was not helped I still look at it as positive. Because no one offered help, it is a chance for me to help myself…I have learnt a lot base on my capacity with a trials and errors. This is why I thank for not helping me. It is really a sincere thank, I repeat.

    By nature I am always acknowledge, appreciate and grateful to all help. Look at questions and answers in the form attached to post #33, you will find more about my genuineness.

    Thanks.
    Viratha
    Last edited by Viratha; Jan 15th, 2009 at 04:52 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
  •  



Click Here to Expand Forum to Full Width