|
-
Dec 9th, 2002, 01:54 PM
#1
Thread Starter
Junior Member
some help plzzz?
i'm trying to search for an exsiting item in lstBox, b4 i add any new ones. if there's the same item in lstBox than just add Quantity, if no then add the item. my code here is not working, so i would like u to check out . also i'd like to delete quanity by inputting a (-) number in txtQuantity.text, how can i do that.
Private Function IsFound(ByVal pstrSearch As String) As Boolean
Dim itemCount As Integer
For itemCount = 0 To lstProduct.Items.Count - 1
'If LCase(pstrSearch) = LCase(lstProduct.Items.Item(itemCount)) Then
If lstProduct.Items.Item(itemCount) Is (cobProduct.SelectedItem) Then
IsFound = True
Exit Function
End If
Next
IsFound = False
End Function
Private Sub cmdAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAdd.Click
Dim itemFound As Boolean
Dim itemCount As Integer
If cobProduct.SelectedIndex <> -1 Then
If txtQuantity.Text = "" Then
MsgBox("please choose a quantity 1 or above")
Else
If IsNumeric(txtQuantity.Text) = False Then
MsgBox(" please insert a number")
Else
quantity = CDbl(txtQuantity.Text)
If IsFound(cobProduct.Text) = False Then
' item not found in lstProduct
MsgBox(" not found")
If quantity > 0 Then
lstQuantity.Items.Add(quantity)
totalQuantity = Val(lblTotalQuantity.Text) + quantity
lblTotalQuantity.Text = CStr(totalQuantity)
lstProduct.Items().Add(cobProduct.Text)
calculation = CDec(Val(txtQuantity.Text) * Val(lblUnitPrice.Text))
lstCost.Items.Add(calculation)
totalCost = (totalCost + calculation)
lblTotalCost.Text = CStr(totalCost)
Else
lstQuantity.Items.Add(lstProduct.SelectedIndex)
lstCost.Items.Add(lstProduct.SelectedIndex)
End If
Else
MsgBox("please input a quantity more than 0")
End If
End If
End If
Else
MsgBox("please select an item")
End If
txtQuantity.Text = ""
txtQuantity.Focus()
End Sub
thanks
-
Dec 9th, 2002, 04:50 PM
#2
What are the Items you are using in the listbox? Strings? Objects?
Try using the ListBox.Items.Contains method. It should return True or false if the item is in there.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|