Question: How do I get my data validation functions to validate my data that is inputted from an input box? This is coded in visual studio

How do I get my data validation functions to validate my data that is inputted from an input box? This is coded in visual studio 2019.

If IsValidData() Then

For i As Integer = 1 To 100 Step 1 'allows users to enter 100 scores

inputData = Convert.ToDouble(InputBox("Input the grade. Input -9 to stop", "Grade Input"))

Me.GetScores(inputData)

If inputData = -9 Then 'allows the user to stop enter scores

Exit For

End If

Next

End If

These are my data validation functions.

Private Function IsPresent(inputData As String, name As String) As Boolean

If InputBox(inputData) = "" Then

MessageBox.Show(name & " is a required field.", "Entry Error")

Return False

Else

Return True

End If

End Function

'check if a number is a double

Private Function IsDouble(inputData As String, name As String) As Boolean

Dim number As Double = 0

If Double.TryParse(InputBox(inputData), number) Then

Return True

Else

MessageBox.Show(name & " must be a double value.", "Entry Error")

Return False

End If

End Function

'checks for valid data range

Private Function IsWithinRange(inputData As String, name As String, min As Double, max As Double) As Boolean

Dim number As Double = CDec(InputBox(inputData))

If number < min OrElse number > max Then

MessageBox.Show(name & " must be between " & min & " and " & max & ".", "Entry Error")

Return False

Else

Return True

End If

End Function

'validates all data input

Private Function IsValidData() As Boolean

Return _

IsPresent() AndAlso

IsDouble(), "Grades") AndAlso

IsWithinRange(), "Range", 0, 100)

End Function

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!