【发布时间】:2014-01-01 10:06:26
【问题描述】:
我的代码出现问题。错误中说我应该在代码中添加New,但我不知道该放在哪里。这是函数的完整代码:
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
Try
Dim TA As New POSCanteenTableAdapters.ItemsTableAdapter
Dim TB = TA.GetDataByBarcode(TextBox1.Text)
If TB.Rows.Count = 0 Then
TextBox2.Text = ""
TextBox3.Text = ""
Button1.Enabled = False
Exit Sub
End If
Button1.Enabled = True
Dim IR As POSCanteen.ItemsRow = TB.Rows(0)
TextBox2.Text = IR.ItemName
TextBox3.Text = IR.SellPrice
Button2.Tag = IR
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical Or MsgBoxStyle.OkOnly)
End Try
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim IR As POSCanteen.ItemsRow = Button1.Tag
Dim RI As New Integer
Dim ItemLoc As Integer = -1
For RI = 0 To CDGV3.Rows.Count - 1
If IR.Barcode = CDGV3.Rows(RI).Cells(0).Value Then
ItemLoc = RI
Exit For
End If
Next
If ItemLoc = -1 Then
CDGV3.Rows.Add(IR.Barcode, IR.ItemName, IR.BuyPrice, IR.SellPrice, 1, IR.SellPrice)
Else
Dim ItemCount As Long = CDGV3.Rows(ItemLoc).Cells(4).Value
ItemCount += 1
Dim NewPrice As Decimal = IR.SellPrice * ItemCount
CDGV3.Rows(ItemLoc).Cells(4).Value = ItemCount
CDGV3.Rows(ItemLoc).Cells(5).Value = NewPrice
End If
TextBox1.Text = ""
TextBox1.Focus()
End Sub
它应该在数据网格中添加一个项目,但不会因为那个错误。我不知道把它放在哪里,因为编译器没有告诉我在哪里。
这是异常消息:Object reference not set to an instance of an object.
【问题讨论】:
-
它在哪里给出错误? VS 会通过鼠标准确地告诉你哪些东西不是什么东西。
-
关于 CDGV3.rows.add(IR.ItemName.IR.BuyPrice,Ir.SellPrice,1,Ir.Sellprice)的部分
-
鼠标悬停在
IR变量上是Nothing吗? -
打开
OPTION STRICT看看有什么问题 -
那个选项在哪里??