[英]VB.NET- Changing .Text property of Textbox throws Null Reference Exception
这必须是微不足道的。 我以此为生,无法弄清楚为什么我会得到这个例外:
System.NullReferenceException未处理Message = Object引用未设置为对象的实例。
这是代码:
Public Class frmMain
Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim counties() As String
counties = {"", "Huntsville, AL", "Madison, AL", "Rural Madison County, AL", "Taft, TN"}
Me.cbCounties.DataSource = counties
Me.lblStatus.Text = "[ Please select a county ]"
Me.lblStatus.Left = Me.ClientSize.Width \ 2 - Me.lblStatus.Width \ 2
End Sub
Private Sub cbCounties_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbCounties.SelectedIndexChanged
Select Case cbCounties.SelectedIndex
Case 1
txtTaxRate.Text = "8.00%" 'Issue is these, when index is changed.
Case 2
txtTaxRate.Text = "8.50%"
Case 3
txtTaxRate.Text = "5.50"
Case 4
txtTaxRate.Text = "9.50%"
Case Else
txtTaxRate.Text = Nothing
End Select
Me.lblStatus.Text = "[ Please enter net amount ]"
Me.lblStatus.Left = Me.ClientSize.Width \ 2 - Me.lblStatus.Width \ 2
End Sub
结束班
救命?
这是你改变它几次后?
设置txtTaxRate = Nothing
以及稍后尝试将txtTaxRate.Text
设置为其他内容将导致一些问题。
您正在将文本框对象设置为空,然后尝试引用其中一个属性。
尝试改变
txtTaxRate = Nothing
至
txtTaxRate.Text = ""
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.