Hello, I basicaly not familiar with vb.net because I'm new to it but I need help for my assingment P.O.S System but I can't fin a way to deduct the amount that you want to remove from the list.
I always have this eror and I don't know if the coding is correct either I tried using SelectedIndex but the selected price of the item I choose didn't appear on the PriceTextBox so I try several ways that I can think of error9
the amount of the item selected in the listbox1 suppose to appear in the PriceTextBox so that when I click the void button it will deduct the total amount from the PriceTextBox but it's not working
POS

can anyone help or give links to same problems..thanks.
these are the coding I used
VOID BUTTON:

Private Sub Button5_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        ListBox1.Items.RemoveAt(ListBox1.SelectedIndex)
        TextBox1.Text = Val(TextBox1.Text) - Val(PriceTextBox.Text)
    End Sub

SELECTING FROM LISTBOX:
I tried to swap from SelectedItem and SelectedIndex and then using them both them swaping their positions but I still can't get it

 Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
        If ListBox1.SelectedItem.Equals("c1 90") Then
            ListBox1.SelectedIndex.Equals("c1 90")
            MealComboBox.Text = "c1"
            PriceTextBox.Text = "90"

        End If
        If ListBox1.SelectedIndex.Equals("c2 100") Then
            ListBox1.SelectedItem.Equals("c2 100")
            MealComboBox.Text = "c2"
            PriceTextBox.Text = "100"

        End If
        If ListBox1.SelectedIndex.Equals("c3 150") Then
            ListBox1.SelectedItem.Equals("c3 150")
            MealComboBox.Text = "c3"
            PriceTextBox.Text = "150"

        End If
        If ListBox1.SelectedIndex.Equals("c4 200") Then
            ListBox1.SelectedItem.Equals("c4 200")
            MealComboBox.Text = "c4"
            PriceTextBox.Text = "200"

        End If
        If ListBox1.SelectedIndex.Equals("b1 390") Then
            ListBox1.SelectedItem.Equals("b1 390")
            MealComboBox.Text = "b1"
            PriceTextBox.Text = "390"

        End If
        If ListBox1.SelectedIndex.Equals("b2 450") Then
            ListBox1.SelectedItem.Equals("b2 450")
            MealComboBox.Text = "b2"
            PriceTextBox.Text = "450"

        End If
    End Sub

Recommended Answers

All 4 Replies

The problem is caused by: ListBox1.Items.RemoveAt(ListBox1.SelectedIndex)
When you remove the item, there is nothing selected and SelectedIndex = -1.

That explains the error, but I have a feeling that your program logic may not be correct.
Is the listbox used to select the meals or is it selected by the combobox and added to the listbox with your "Add" button? The latter case makes sense to me. However, you are traping a change in the listbox and setting the text of the combobox.

Thank for the reply, I will try to change it to see if it will work.

can you please just tell me your requirements , not code or what you have done so far , just to the point tell me your requirements.

thanks for your suggestion TnTinMN, just as you said the remove command was wrong and I also change the logic. Sorry if I put the wrong logic of the program I actually change it 3hrs after posting then my net connection was lost and I forgot to change it here.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.