Results 1 to 2 of 2

Thread: [RESOLVED] how to output multiple checkboxes to same line in listbox?

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2010
    Posts
    3

    Resolved [RESOLVED] how to output multiple checkboxes to same line in listbox?

    I'm trying to make a lotto 649 program. There are 49 checkboxes for the user to select numbers to make a ticket. When the user hits the submit button, the program should output the six numbers to the same line in a listbox. How do you do this? For example, if the user decides to purchase two tickets, I'd like the output of the listbox to look like this:

    1) 4, 49, 24, 22, 30, 9
    2) 47, 32, 30, 3, 1, 5

    Code:
    Private Sub cmdSubmit_Click()
    
    Static t As Integer
    t = t + 1
    
    For i = 0 To 6
    
    If optNum(i).Value = 1 Then
        List1.AddItem t & ") " & optNum(i).Caption
    End If
    
    Next
    
    End Sub

  2. #2

    Thread Starter
    New Member
    Join Date
    Sep 2010
    Posts
    3

    Re: [RESOLVED] how to output multiple checkboxes to same line in listbox?

    Now I need help with matching the user selected numbers and winning numbers.

    As mentioned before there is a listbox with the numbers for each ticket. eg.

    1) 4 49 2 30 24 5
    2) 47 44 32 1 9 5

    There is a button (cmdCheck) that generates the winning numbers and displays it in six labels / stores it in an array. I need to make it search for matching numbers for each ticket and than display it in another listbox.

    For example, if the generated numbers are 4 33 5 22 3 6, it should find matching numbers for each ticket in the first listbox and than output the matching numbers to listbox2 such as

    1) 4 5
    2) 5

    Don't mind optNum since I just tested the code with a few checkboxes.

    Code:
    Dim j As Boolean
    
    Private Sub cmdCheck_Click()
    
        Dim arrNum(5) As Integer
        Dim lottoNum As Integer, intCount As Integer, intCheck As Integer
        
        For intCount = 0 To 5                   'selection counter
            lblNum(intCount).Caption = ""
            
    Start:
            Randomize (Timer)                   'random for 1 to 49
            lottoNum = Int((49 * Rnd) + 1)
                
            For intCheck = 1 To 6           'if number is not unique then randomizes again
                If lottoNum = arrNum(intCheck - 1) Then
                    GoTo Start
                End If
            Next intCheck
                
            arrNum(intCount) = lottoNum         'stores in array
            lblNum(intCount).Caption = lottoNum     'outputs to labels
    Next
    
    
    End Sub
    
    Private Sub cmdDone_Click()     'closes program
    
    End
    
    End Sub
    
    Private Sub optNum_Click(Index As Integer)      'no more than six numbers can be selected at a time, displays error message if a user tries to select more
                                                    'six numbers has to be selected or it will not let user submit a ticket
    Dim i As Integer
    Dim c As Integer
    
    For i = 0 To 6
        c = c + IIf(optNum(i).Value = vbChecked, 1, 0)
    Next
        If c > 6 Then
            MsgBox "You may only select a maximum of six numbers."
            optNum(Index).Value = 0
        ElseIf c = 6 Then
            j = True
        End If
    
    End Sub
    
    Private Sub cmdSubmit_Click()
    
    Static t As Integer
    Dim s As String
    Dim i As Integer
    
    If j = True Then
    
        t = t + 1                           'outputs the six selected numbers to listbox
        s = t & ") "
        
        For i = 0 To 6
            If optNum(i).Value = 1 Then
                s = s & "   " & optNum(i).Caption & "    "
            End If
        Next
        List1.AddItem s
    Else
        MsgBox "You must select six numbers."         'displays error if six numbers are not selected
    End If
    
    For i = 0 To 6                  'clears selections
        optNum(i).Value = 0
    Next
        j = False
    
    End Sub

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