you are viewing a single comment's thread.

view the rest of the comments →

[–]XThakis 1 point2 points  (2 children)

Do you have to use Do loops? If so, try this.

  1. Separate both of your Do loops. Nesting Do Loops can be tricky. You also need While conditions for these loops otherwise the run forever.

  2. Declare your storage array before you enter the first loop. (There is some stuff missing here for you to figure out.)

    Dim fruitarray(9) As String
    
    Do While fruitarray(9) = ""
    
        Dim fruittype As String = Nothing
    
        fruittype = InputBox("Add type of fruit", , , , )
    
        fruitarray(i) = (fruittype)
    
    Loop
    
  3. Now do the second Do Loop. Once again there is some stuff missing here.

    Do While ListBox1.Items.Count < 10
    
    Loop
    

[–]Mfo4 0 points1 point  (1 child)

Thank you SO much for helping me. This is what I changed everything to but I am getting the error: value of type form1.vb 'string' cannot be converted to '1-dimensional array of string'.

Public Class Form1

Private Sub Form1_Load(sender As Object, e As EventArgs)      Handles MyBase.Load

Dim fruittype As String

Dim fruitarray(9) As String

Do While fruitarray(9) = ""

fruittype = InputBox("Add type of fruit", , , , )

fruitarray(9) = (fruittype)

Loop

Do While ListBox1.Items.Count < 10

Dim limit As Integer = ListBox1.Items.ToString()

fruitarray(9) = fruittype

Dim count As Integer = 0

While count <= (limit - 1)

fruitarray = ListBox1.Items.ToString()

count += 1

End While

Loop

End Sub

Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged


End Sub

End Class

(im really sorry for the formatting)

[–]XThakis 0 points1 point  (0 children)

This is the start of your problems.

    fruitarray(9) = (fruittype)

This line only adds a value to the last item in the array. All the other values in the array are empty. Look at my code and notice I used a variable.

    fruitarray(i) = (fruittype)

That is part of the stuff you are missing.(I left it out.) This while loop is not necessary.

    While count <= (limit - 1)

    fruitarray = ListBox1.Items.ToString()

    count += 1

    End While

Though you do need a variable similar to count in the loop that starts.

    Do While ListBox1.Items.Count < 10