当我尝试“清除”程序中的文本框时,我遇到了以下问题。这是一个初学者的课程,所以我应该能够用我到目前为止所学的内容来回答修复错误。每当我按 NextYear 时,该程序基本上都会计算利率和资本增长。当我按下“清除”按钮时,它会显示错误并将我指向事件capital = CDbl(txtInitialCap.Text)
下的语法。txtRate_TextChanged
Private year As Integer
Private capital As Double
Private Sub btnNextYear_Click(sender As Object, e As EventArgs) Handles btnNextYear.Click
Dim interestAmount, interestRate As Double
'
' Assign value to InterestRate variable from text property
'
interestRate = CDbl(txtRate.Text)
'
' Calculate new values for year, interest amount and capital
'
year = year + 1
interestAmount = capital * interestRate
capital = capital + interestAmount
'
' Assign the values to the textboxes
'
txtYear.Text = year
txtInterest.Text = interestAmount
txtCapital.Text = capital
Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click
txtInitialCap.Text = vbNullString
txtRate.Text = vbNullString
txtYear.Text = vbNullString
txtInterest.Text = vbNullString
txtCapital.Text = vbNullString
End Sub
Private Sub txtInitialCap_LostFocus(sender As Object, e As EventArgs) Handles txtInitialCap.LostFocus
'
' Reinitialise the capital variable since probably it was changed
'
capital = CDbl(txtInitialCap.Text)
End Sub
Private Sub txtInitialCap_TextChanged(sender As Object, e As EventArgs) Handles txtInitialCap.TextChanged
'
' Reinitialise the year variable and the textboxes
'
year = 0
txtYear.Text = vbNullString
txtInterest.Text = vbNullString
txtCapital.Text = vbNullString
End Sub
Private Sub txtRate_TextChanged(sender As Object, e As EventArgs) Handles txtRate.TextChanged
year = 0
capital = CDbl(txtInitialCap.Text)
txtYear.Text = vbNullString
txtInterest.Text = vbNullString
txtCapital.Text = vbNullString
End Sub