VB에서 매우 익숙하며 숙제를하고 있습니다. 3 개의 텍스트 상자에서 오는 값이 계산에 유효한 값인지 확인하기 위해 중첩 된 try/catch 블록을 설정하려고합니다. 나는 "End of statement expected"오류가 나타나는 이유를 알 수없는 것처럼 멈추었습니다. try 블록의 모든 3 줄에는 그 아래에 구불 구불 한 선이 있습니다. 사람으로도움 요청/예상치 못한 문제가 발생했습니다.
Private Sub Calculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Calculate.Click
Dim FutureValueDecimal, InvestmentAmountDecimal, InterestRateDecimal As Decimal
Dim YearsInteger As Integer
Try InvestmentAmountDecimal = Decimal.Parse(InvestmentAmountTextBox.text)
Try InterestRateDecimal = Decimal.Parse(InterestRateTextBox.text)
Try YearsInteger = Integer.Parse(yearsTextBox.text)
Catch InvalidYears As FormatException
MsgBox("Please enter a valid number of years", MsgBoxStyle.Exclamation, "Error")
YearsTextBox.SelectAll()
End Try
Catch InvalidInterest As FormatException
MsgBox("Please enter a valid interest rate.", MsgBoxStyle.Exclamation, "Error")
InterestRateTextBox.SelectAll()
End Try
Catch InvalidAmount As FormatException
MsgBox("Please enter a valid investment amount.", MsgBoxStyle.Exclamation, "Error")
End Try
FutureValueDecimal = InvestmentAmountDecimal * (1D + InterestRateDecimal)^YearsInteger
FutureValueTextBox.Text = FutureValueDecimal.ToString("C")
End Sub
'Try '와 다음 문장 (예 :'InvestmentAmountDecimal = Decimal.Parse (InvestmentAmountTextBox.text)') 사이에 줄 바꿈을하십시오. – someone
나는 그것을 시도하고 그것은 작동하지 않습니다. 이상한 것은 비록 내가 2 개의 내부 try/catch를 주석 처리하고 외부에 'InvestmentAmountDecimal + = 1'과 같은 단순한 것을 시도하더라도, 나는 여전히 같은 오류를 얻는다. – Kris
@Kris 당신이 사용하고있는 책에는 seprate 줄에 있어야하고 같은 줄에 그 줄을 보여줄 필요가 없다는 두 가지 이유가 있습니다. 1) 저자는 더 잘 알지 못했다. 2) 발행인이 서식을 변경했고 저자가이를 수정하지 않았습니다 (이유 1 때문일 수 있음). 이 책에는 저자 또는 발행인을위한 연락처 전자 메일 주소가 있어야합니다 ... 향후 인쇄물에 맞게 수정하려면 뭔가를 보내십시오! –