Associate
- Joined
- 22 May 2004
- Posts
- 1,792
- Location
- N.Ireland
Hi guys am doing a program for tech and have been told to add validation.Ie a message box error if user inputs the incorrect value into the text boxes. The user should be entering Int or doubles. So if a user adds text how can I get the program to throw up an error. The code in question is below.
Any help would be appricated
Code:
Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
'Declare Local Variables required for calculations
Dim dblInterest, dblInvested, dblYears As Double
Dim dblInterestEarned, dblTotal As Double
'Input Values from User
dblInterest = Val(Me.txtInterest.Text)
dblInvested = Val(Me.txtAmount.Text)
dblYears = Val(Me.txtYears.Text)
'Perform Calculations based upon input Values
dblInterestEarned = dblInvested * (1 + dblInterest / 100) ^ dblYears
dblTotal = dblInterestEarned + dblInvested
'Output results to Form
Me.txtInterestEarned.Text = CStr(dblInterestEarned)
Me.txtAmountEarned.Text = CStr(dblTotal)
Any help would be appricated