1 Replies - 300 Views - Last Post: 22 February 2019 - 02:02 AM Rate Topic: -----

#1 deannas99   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 21-January 19

How do I get data to start entering in second listbox?

Posted 21 February 2019 - 12:19 PM

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
Dim students(6) As Integer

  students(0) = "" &inputtextbox.Text
  students(1) = "" &inputtextbox.Text
  students(2) = "" &inputtextbox.Text
  students(3) = "" &inputtextbox.Text
  students(4) = "" &inputtextbox.Text
  students(5) = "" &inputtextbox.Text
  students(6) = "" &inputtextbox.Text


And
  If Employee1.Count = 7 Then
        If InputTextbox.Text >= 0 AndAlso InputTextbox.Text <= 1000 Then
            Employee2.Add(InputTextbox.Text)
            EmployeeListbox2.DataSource = Nothing
            EmployeeListbox2.DataSource = Employee1
            InputTextbox.Clear()
        End If
    End If


This is my code so now but I think something is still missing... Any help would be much appreciated

Dim CurrentListbox As Integer
    Private Sub EnterButton_Click(sender As Object, e As EventArgs) Handles EnterButton.Click
        Dim UnitsArray As String()
        Dim output As Integer

        UnitsArray = Split(InputTextbox.Text, ",")
        For output = 1 To UnitsArray.Count
            If output >= 1 And output <= 7 Then
                Select Case CurrentListbox
                    Case 0 To 6
                        EmployeeListbox1.Items.Add(UnitsArray(output - 1))


                    Case 7 To 13
                        EmployeeListbox2.Items.Add(UnitsArray(output - 1))

                    Case 14 To 20
                        EmployeeListbox3.Items.Add(UnitsArray(output - 1))

                End Select

            ElseIf output = 7 Then
                If CurrentListbox < 7 Then
                    CurrentListbox = CurrentListbox + 1
                Else
                    ' last one - no more listboxes
                End If
                Exit For
            End If
        Next
        InputTextbox.Text = ""
    End Sub

    Private Sub EmployeeListbox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles EmployeeListbox1.SelectedIndexChanged

    End Sub

    Private Sub AverageUnitsShippedByEmployeeForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        CurrentListbox = 1
        EmployeeListbox1.Items.Clear()
        EmployeeListbox2.Items.Clear()
        EmployeeListbox3.Items.Clear()
    End Sub



Thanks!

Is This A Good Question/Topic? 0
  • +

Replies To: How do I get data to start entering in second listbox?

#2 andrewsw   User is offline

  • Stealth IT
  • member icon

Reputation: 6737
  • View blog
  • Posts: 27,741
  • Joined: 12-December 12

Re: How do I get data to start entering in second listbox?

Posted 22 February 2019 - 02:02 AM

What happens, or doesn't happen, when you run your code? Are there errors?

You are collecting 21 values, in sequence, and using them to populate 3 listboxes in sequence. Given this, I don't think it is necessary to attempt to store how many values have been entered so far. I would probably,

On pressing Enter,
Check if the number of items in listbox 1 is less than 7,
If it is, then add the value to it,
Otherwise, check if the number of items in listbox 2 is less than 7,
If it is, then add the value to it,
Perform the same check for listbox 3,
If less than 7, add to it,
Otherwise, we are done and can calculate averages and display the results somewhere.

It is up-to you, though, to determine how sophisticated this needs to be. That is, whether you should include arrays or classes - a data model. If it is just a question of using these form controls and events, and iterating listbox items, then it can be done without any formal data structures.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1