簡體   English   中英

VB.NET-更改Textbox的.Text屬性會拋出Null Reference Exception

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM