locked
value cannot be null parameter name: item RRS feed

  • Question

  • User1521734736 posted

    ok so I want my program to avoid from crashing if the 'user' didn't check a certain thing, so I want to be able to click the add button without it crashing on me because you cannot select 'null'

    Private Sub btnAdd_Click(sender As System.Object, e As System.EventArgs) Handles btnAdd.Click


    'clear out grand total variable

    'so if user changes mind it does not contain
    'old values
    total = 0
    'as long as the variable contains something!
    If Pizza <> "" Then

    End If
    ' add up the decimal variables
    'for a grand total price
    total = total + PizzaPrice
    total = total + Pizzas(0)
    total = total + Pizzas(1)
    total = total + Pizzas(2)
    total = total + Pizzas(3)
    total = total + Pizzas(4)
    'clear the list box
    'in case user changes
    'items selected
    TotalPrice.Items.Clear()
    ' add title
    TotalPrice.Items.Add("Pizza Selected:--")
    TotalPrice.Items.Add(Pizza)

    For i As Integer = 0 To 4

    Next
    If Not Pizzas(i) = "" Then

    TotalPrice.Items.Add(Pizzas(i))
    End If

    If TwoSizes <> "" Then

    End If

    total = total + SizesPrice
    total = total + SizesTotalPrice(0)
    total = total + SizesTotalPrice(1)
    TotalPrice.Items.Add("Size Selected:--")
    TotalPrice.Items.Add(TwoSizes)

    For i As Integer = 0 To 1


    If Not SizesTotalPrice(i) = "" Then
    TotalPrice.Items.Add(SizesTotalPrice(i))

    End If


    Next

    If base <> "" Then


    total = total + baseprice
    total = total + twobases(0)
    total = total + twobases(1)
    TotalPrice.Items.Add("Base Selected:--")
    TotalPrice.Items.Add(base)
    For i As Integer = 0 To 1

    If Not twobases(i) = "" Then
    TotalPrice.Items.Add(twobases(i))
    End If
    Next

    total = total + drinkprice
    total = total + twodrinks(0)
    total = total + twodrinks(1)
    total = total + twodrinks(2)
    TotalPrice.Items.Add("Drink Selected:--")
    TotalPrice.Items.Add(drink)
    For i As Integer = 0 To 2

    If Not twodrinks(i) = "" Then
    TotalPrice.Items.Add(twodrinks(i))

    End If
    Next

    total = total + toppingprice
    total = total + toppingprice1
    total = total + toppingprice2
    total = total + toppingprice3
    total = total + toppings(0)
    total = total + toppings(1)
    total = total + toppings(2)
    total = total + toppings(3)
    TotalPrice.Items.Add("Topping Selected:--")
    TotalPrice.Items.Add(topping)
    TotalPrice.Items.Add(topping1)
    TotalPrice.Items.Add(topping2)
    TotalPrice.Items.Add(topping3)

    For i As Integer = 0 To 3

    If Not toppings(i) = "" Then
    TotalPrice.Items.Add(toppings(i))
    End If
    Next

    'add a dotted line
    TotalPrice.Items.Add("----------")
    'etc etc
    TotalPrice.Items.Add("Total £" & total)

    End If

    End Sub

    Thursday, May 9, 2013 7:31 AM

Answers

  • User1508394307 posted

    Where do you get your error and how exactly its message looks like? There is no reference to "item" as mentioned in the title of your post.

    The code is somehow strange and incomplete. For example, 

    If Pizza <> "" Then
    ------------what should happen here?
    End If
    ...
    TotalPrice.Items.Add(Pizza) ------ why you add an empty Pizza (if Pizza = "")

    then

    For i As Integer = 0 To 4
    -------- what this enumeration is for?
    Next

    and so on...

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 9, 2013 1:30 PM