Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In visual basic, I need help adding code to make a error message when the user i

ID: 3806529 • Letter: I

Question

In visual basic, I need help adding code to make a error message when the user inputs value incorrectly.
   "Must enter a Description."
   "Year Purchased is not numeric."
   "Year Purchased is not between 1900 and 9999"
   "Purchase Amount is not numeric."
   "Years to Depreciate is not numeric."
   "Number of years must be between 1 and 999."

Here is my code:

Public Class Form1
Dim description As String
Dim method As String
Dim dblAmountToDepr As Double
Dim intNumberYears As Integer
Dim dblCurrentYearAmountToDepr As Double
Dim dblCurrentYearStart As Double

Private Sub btnStraight_Click(sender As Object, e As EventArgs) Handles btnStraight.Click
method = "straight-line"
writeDescription()
dblCurrentYearAmountToDepr = dblAmountToDepr / intNumberYears
YearlyDescription()
End Sub

Private Sub btnDoubleDecline_Click(sender As Object, e As EventArgs) Handles btnDoubleDecline.Click
method = "double-declining-balance"
writeDescription()
dblCurrentYearAmountToDepr = dblCurrentYearStart * (2 / intNumberYears)
YearlyDescription()
End Sub

Public Sub writeDescription()
description = txtDescription.Text
dblCurrentYearStart = CInt(txtStartYear.Text)
dblAmountToDepr = CDbl(txtAmountToDepre.Text)
intNumberYears = CInt(txtYearstoDepr.Text)

lstOutput.Items.Clear()
lstOutput.Items.Add("Description: " & description)
lstOutput.Items.Add("Year of purchase: " & dblCurrentYearStart)
lstOutput.Items.Add("Cost: " & FormatCurrency(dblAmountToDepr))
lstOutput.Items.Add("Estimated life: " & intNumberYears)
lstOutput.Items.Add("Method of depreciation: " & method)
lstOutput.Items.Add("")
End Sub

Public Sub YearlyDescription()
Dim dblCurrentYearEnd As Double = 0
Dim intCalYearStart As Integer = dblCurrentYearStart + intNumberYears
For intYr As Integer = dblCurrentYearStart To intCalYearStart
lstOutput.Items.Add("Value at beginning of " & intYr & ": " & FormatCurrency(dblAmountToDepr))
dblAmountToDepr -= dblCurrentYearAmountToDepr
lstOutput.Items.Add("Amount of depreciation during " & intYr & ": " & FormatCurrency(dblCurrentYearAmountToDepr))
dblCurrentYearEnd += dblCurrentYearAmountToDepr
lstOutput.Items.Add("Total depreciation at end of " & intYr & ": " & FormatCurrency(dblCurrentYearEnd))
lstOutput.Items.Add("")
Next
End Sub
End Class

Depreciation term Cost Year of purchase Estimated life of item years): Straight-Line Method Double-Declining-Balance Method

Explanation / Answer

Ans:

Ans: You can add this following code to get error messages(box) if entered values does not match.

// If description is empty

  

Select Case txtDescription.Text

Case ""

MsgBox("Please enter value for Description")

txtDescription.Focus()

Case "<Enter the Item Description>"

MsgBox("Please enter Description")

txtDescription.Focus()

Exit Sub

End Select

// If year purchased is not numeric

Select Case txtYearPurchased.Text

Case Is = txtYearPurchased.Text

If IsNumeric(txtYearPurchased.Text) = False Then

MsgBox("please enter numeric value")

txtYearPurchased.Focus()

Exit Sub

End If

End Select

// if year purchased is not between 1900 and 1999

Select Case txtYearPurchased.Text

Case Is = txtYearPurchased.Text

If txtYearPurchased.Text < 1900 Or txtYearPurchased.Text > 9999 Then

MsgBox("Enter year between 1900 and 9999")

txtYearPurchased.Focus()

Exit Sub

End If

End Select

// purchase amount is not numeric

Select Case txtPurhaseAmount.Text

Case Is = txtPurhaseAmount.Text

If IsNumeric(txtPurhaseAmount.Text) = False Then

MsgBox("Entered value must be numeric")

txtPurhaseAmount.Focus()

Exit Sub

End If

End Select

// deprc is not numeric

Select case txtYearDepriciate.Text

Case Is = txtYearDepriciate.Text

If IsNumeric(txtYearDepriciate.Text) = False Then

MsgBox("Depriciate year must be numeric")

txtYearDepriciate.Focus()

//year depric

Select Case txtYearDepriciate.Text

Case Is = txtYearDepriciate.Text

If txtYearDepriciate.Text < 1 Or txtYearDepriciate.Text > 999 Then

MsgBox("Years to Depreciate must be in between 1 and 999")

txtYearDepriciate.Focus()

Exit Sub

End If

End Select

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote