Dim num As Integer
Dim basket_cost As Currency
Dim costing As Currency

Private Sub Command1_Click()

    If Item_cost.Text = "" Then

        MsgBox ("please show Item Cost")

    ElseIf item_to_add.Text <> "" Then

        basket_items.AddItem item_to_add.Text

        cost.AddItem costing

    End If

    num = num + 1

    item_to_add.SetFocus

    total_items.Caption = num

    basket_cost = basket_cost + Val(Item_cost.Text)

    cost_of_basket.Caption = basket_cost

    item_to_add.Text = ""

    Item_cost.Text = ""

End Sub

Private Sub Command2_Click()

    If basket_items.ListIndex <> -1 Then

        cost.ListIndex = basket_items.ListIndex

        basket_items.RemoveItem (basket_items.ListIndex)

        basket_cost = basket_cost - Val(cost.List(cost.ListIndex))

        cost_of_basket.Caption = basket_cost

        cost.RemoveItem (cost.ListIndex)

        num = num - 1

        total_items.Caption = num

    End If

End Sub

Private Sub Command3_Click()

    basket_items.Clear

    cost.Clear

    item_to_add.Text = ""

    num = 0

    cost_of_basket.Caption = 0

    total_items.Caption = 0

End Sub

Private Sub basket_items_Click()

    If item_to_add.Text <> "" Then

        'basket_items.text = basket_items.List(basket_items.ListIndex)
        basket_items.List(basket_items.ListIndex) = item_to_add.Text

    End If

    ' MsgBox (" This is number " & basket_items.ListIndex + 1 & " in the list")

End Sub

Private Sub Item_cost_Change()

    valid_char = IsNumeric(Item_cost.Text)

    If Not valid_char Then

        Beep
        Item_cost.Text = ""

    End If

    costing = Format$(Val(Item_cost.Text), "£#,##0.00")

End Sub

Back to vb6 exercises