none
How to get input to switch to a second listbox after 7 numbers are entered in the first listbox? RRS feed

  • Question

  • Hi! So I've been working on this assignment for school and I'm slightly stuck. I'm supposed to create this form to calculate average units shipped by employees. I have three different employees so three different listboxes to accept the data but only one input textbox. The form is supposed to only accept 7 numbers in the first listbox before moving onto the second listbox, getting 7 numbers there, then going to the third. But I don't know how to do that

    I've tried
    1 Dim students(6) As Integer
    2  
    3   students(0) = "" &inputtextbox.Text
    4   students(1) = "" &inputtextbox.Text
    5   students(2) = "" &inputtextbox.Text
    6   students(3) = "" &inputtextbox.Text
    7   students(4) = "" &inputtextbox.Text
    8   students(5) = "" &inputtextbox.Text
    9   students(6) = "" &inputtextbox.Text


    And
    1 If Employee1.Count = 7 Then
    2       If InputTextbox.Text >= 0 AndAlso InputTextbox.Text <= 1000 Then
    3           Employee2.Add(InputTextbox.Text)
    4           EmployeeListbox2.DataSource = Nothing
    5           EmployeeListbox2.DataSource = Employee1
    6           InputTextbox.Clear()
    7       End If
    8   End If


    This is my code so now but I think something is still missing... Any help would be much appreciated
    01 Dim CurrentListbox As Integer
    02     Private Sub EnterButton_Click(sender As Object, e As EventArgs) Handles EnterButton.Click
    03         Dim UnitsArray As String()
    04         Dim output As Integer
    05  
    06         UnitsArray = Split(InputTextbox.Text, ",")
    07         For output = 1 To UnitsArray.Count
    08             If output >= 1 And output <= 7 Then
    09                 Select Case CurrentListbox
    10                     Case 0 To 6
    11                         EmployeeListbox1.Items.Add(UnitsArray(output - 1))
    12  
    13  
    14                     Case 7 To 13
    15                         EmployeeListbox2.Items.Add(UnitsArray(output - 1))
    16  
    17                     Case 14 To 20
    18                         EmployeeListbox3.Items.Add(UnitsArray(output - 1))
    19  
    20                 End Select
    21  
    22             ElseIf output = 7 Then
    23                 If CurrentListbox < 7 Then
    24                     CurrentListbox = CurrentListbox + 1
    25                 Else
    26                     ' last one - no more listboxes
    27                 End If
    28                 Exit For
    29             End If
    30         Next
    31         InputTextbox.Text = ""
    32     End Sub
    33  
    34     Private Sub EmployeeListbox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles EmployeeListbox1.SelectedIndexChanged
    35  
    36     End Sub
    37  
    38     Private Sub AverageUnitsShippedByEmployeeForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    39         CurrentListbox = 1
    40         EmployeeListbox1.Items.Clear()
    41         EmployeeListbox2.Items.Clear()
    42         EmployeeListbox3.Items.Clear()
    43     End Sub
    Thursday, February 21, 2019 10:23 PM

All replies

  • Hi

    Whatever you do, DO NOT post code line numbers, or, post code as an Image. Both of those make it too hard to copy paste and so will likely not get much interest from those you ask to help. Use a Code Block (like this) for code.

    *

    Here is one way (of many possibilities)

    ' Form1 with Button1, TextBox1
    ' and 3 ListBoxesn(1,2,3)
    Option Strict On
    Option Explicit On
    Public Class Form1
      Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim tb As String = Trim(TextBox1.Text)
        If tb.Length > 0 Then
          Select Case ListBox1.Items.Count
            Case < 7
              ListBox1.Items.Add(tb)
            Case Else
              Select Case ListBox2.Items.Count
                Case < 7
                  ListBox2.Items.Add(tb)
                Case Else
                  Select Case ListBox3.Items.Count
                    Case < 7
                      ListBox3.Items.Add(tb)
                    Case Else
                      MessageBox.Show("Sorry-mall full up!")
                  End Select
              End Select
          End Select
        End If
        TextBox1.Text = Nothing
      End Sub
    End Class


    Regards Les, Livingston, Scotland

    • Proposed as answer by Ashidacchi Friday, February 22, 2019 4:22 AM
    Thursday, February 21, 2019 11:01 PM
  • YOU ARE MY HERO! Thank you so much!!
    Thursday, February 21, 2019 11:41 PM
  • Hi,

    If you resolve the issue,  please mark the helpful as answer.

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, February 22, 2019 1:14 AM