VB.net 列表框删除项目

VB.net listBox removing items

当我 运行 这段代码时,它给我一个错误,提示值不能为 null

If (A >= 1) Then
    Item1 = fish
    ListBox1.Items.Add(Item1)
Else
    If (A = 0) Then
        If ListBox1.Items.Contains(Item1) = True Then
            While ListBox1.Items.Contains(Item1) = True
                ListBox1.Items.Remove(Item1)
            End While
        End If
    End If
End If

错误出现在这一行

If ListBox1.Items.Contains(Item1) = True Then

所有整数都已经变暗了

我想做的是是否应删除包含项目 1 的列表框

如果我给 A 值 1 然后将其更改为 0,代码就可以工作

但如果我从一开始就将 A 值设为 0,代码将会崩溃

请帮忙

谢谢

改变

If ListBox1.Items.Contains(Item1) = True Then

If Item1 IsNot Nothing AndAlso ListBox1.Items.Contains(Item1) Then