“使用新关键字创建对象实例”

时间:2013-05-07 04:52:15

标签: vb.net

我不确定这部分程序有什么问题。每次运行时都会显示一条错误消息:

  

对象引用未设置为对象的实例

cc.RawDataString.IndexOf("B")行。

代码:

Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As  System.EventArgs) Handles btnSubmit.Click
    Dim cc As New CreditCard

    Dim posB, posC1, posC2, posBlackSlash As Integer

    posB = cc.RawDataString.IndexOf("B")
    posC1 = cc.RawDataString.IndexOf("^")
    posC2 = cc.RawDataString.IndexOf("^", posC1 + 1)
    posBlackSlash = cc.RawDataString.IndexOf("/")

    cc.RawDataString = txtRawData.Text
    lblCCNumber.Text = cc.Number

    lblCCNumber.Text = cc.RawDataString.Substring(posB + 1, posC1 - posB - 1)
    lblLname.Text = cc.RawDataString.Substring(posC1 + 1, posBlackSlash - (posC1 + 1))
    lblFName.Text = cc.RawDataString.Substring(posBlackSlash + 1, posC2 - (posBlackSlash + 1))
    lblYear.Text = cc.RawDataString.Substring(posC2 + 1, 2)
    lblMonth.Text = cc.RawDataString.Substring(posC2 + 3, 2)

End Sub

1 个答案:

答案 0 :(得分:3)

在您将其设置为某个内容之前,您似乎引用了cc.RawDataString