I have a series of text boxes in a table to gather input as below:
The user will input a target and actual value for each measurement point they require. I would then like to validate the actual values against the target values based upon the tolerance inputted in the tolerance textbox. The tolerance will be the same for all measurement points inputted, however the user will not always input all 10 measurement points.
I have also created a very basic class containing a function that accepts the target, actual and tolerance values then returns a Boolean depending on whether the actual value is within tolerance. I realise I could use this with a ruck load of if statements to check each textbox for input then use the class to perform the validation, however this seems like a lot of code repetition and a bit crude. My question being is there a better way I can perform this validation?
Public Class TolerenceHelper Public Function IsInTolerence(ByVal target As Integer, ByVal actual As Integer, ByVal tolerence As Integer) As Boolean Dim upper As Integer = target + tolerence Dim lower As Integer = target - tolerence If actual < lower OrElse actual > upper Then Return False Else Return True End If End Function
Calling the function as below:
Dim m1 As TolerenceHelper Dim flag As Boolean = True m1 = New TolerenceHelper If m1.IsInTolerence(Integer.Parse(txtT1.Text), Integer.Parse(txtA1.Text), Integer.Parse(txtTolerance.Text)) = False Then flag = False End If If flag = False Then lblTest.Text = "Out of tolerance" Else lblTest.Text = "In tolerance" End If