[2005] Numeric Counter and Listbox help.
Hey, been having some trouble with a program I am currently trying to write.
This is what i have so far:
I have a Numericupdown counter.
I have a Listbox.
When the counter changes i add an item to the listbox.
Code:
If HACCount.Value > 0 Then
Orderbox.Items.Add("Hello" & (HACCount.Value))
end if
This code works fine at the moment.
HACCount.value is the numericupdown counter.
So when I click up on the counter once the listbox will display:
Hello1
Then if i click it so its number 2 it will display:
Hello1
Hello2
Here is a screenshot it better explains it.
http://img209.imageshack.us/img209/2015/testgp2.jpg
What I'm trying to do is not add another item but edit the first item.
So when the numeric counter goes to 1 "Hello1" is displayed.
When the numeric counter does to 2 "Hello2" is displayed NOT "Hello1 Hello2"
Hope this makes sense. This is part of what i need for a POS terminal I'm creating at the moment. If there is an easier way to do this please let me know.
Thanks.
Re: [2005] Numeric Counter and Listbox help.
Why use a listbox if you are not going to list values and just keep overwriting the same item ?
Re: [2005] Numeric Counter and Listbox help.
If you keep calling Add then you're going to keep adding items. Ask yourself what you physically want to do.
Quote:
If there is no item in the ListBox then add an item. If there is an item then change that existing item to the new value.
Now write some pseudo-code to implement that, then write some VB code to implement the pseudo-code.
Re: [2005] Numeric Counter and Listbox help.
Quote:
Originally Posted by user name
Why use a listbox if you are not going to list values and just keep overwriting the same item ?
There will not only be 1 item in the listbox. There will be numerous items eg.
for a pizza pos system:
Someone might order 5 cokes and 4 pizzas.
When i try and scroll up to 5 on the numeric counter for coke it will add:
Coke X 1
Coke X 2
Coke X 3
Coke X 4
Coke X 5
I want to only have Coke X 5 in the listbox.
I cannot clear the items in the box and then add the next item because if there are other items they will be removed as well.
Quote:
If there is no item in the ListBox then add an item. If there is an item then change that existing item to the new value.
How do i check eg. if a Coke has already been ordered? Because i cannot check the first index as another item may be in that slot.
if a coke is in there then how do i edit the item.
Thanks
Re: [2005] Numeric Counter and Listbox help.
Again, ask yourself how you would do it physically. You would look at each item in the list to see if one began with "Coke" and, if it did, you would replace it, otherwise you'd add a new item. Programming is not divorced from physical reality. It's just an implementation of physical reality.
Re: [2005] Numeric Counter and Listbox help.
Quote:
Originally Posted by jmcilhinney
Again, ask yourself how you would do it physically. You would look at each item in the list to see if one began with "Coke" and, if it did, you would replace it, otherwise you'd add a new item. Programming is not divorced from physical reality. It's just an implementation of physical reality.
Ok i understand what you mean, but i would not know how to code it. what is the code to check if an item began with coke? and what is the code to replace the item?
Thanks.