I am taking VB.NET programming and am at wits end with trying to figure out a function for both numeric and range validation. I was hoping someone could explain it better than my book. The exercise question says to add a function that will validate numeric and range using order total as the argument and return a value of 0 if it's valid data, 1 if it is not numeric, and 2 if it's out of the range. The calling procedure should process the data or display an error message based on the value returned by the function. It also says to move the range checking variables to the module level so they're available to both the function and calling procedure. I can get one validation to work but can't figure out how to get both to work together. I am so frustrated I want to give up. If someone can help I would really appreciate it. Thanks.

VB Code:
  1. Private Sub btnCalculate_Click(ByVal sender As System.Object, _
  2.         ByVal e As System.EventArgs) Handles btnCalculate.Click
  3.  
  4.         Const dMinOrderTotal As Decimal = 10
  5.         Const dMaxOrderTotal As Decimal = 10000
  6.  
  7.         Dim dOrderTotal As Decimal
  8.         Dim dDiscountPct As Decimal
  9.         Dim dDiscountAmount As Decimal
  10.         Dim dInvoiceTotal As Decimal
  11.  
  12.         If IsNumeric(txtOrderTotal.Text) Then
  13.             If txtOrderTotal.Text > dMinOrderTotal And _
  14.             txtOrderTotal.Text < dMaxOrderTotal Then
  15.                 dOrderTotal = txtOrderTotal.Text
  16.                 dOrderTotal = Math.Round(dOrderTotal, 2)
  17.  
  18.                 dDiscountAmount = DiscountAmount(dOrderTotal)
  19.  
  20.                 dInvoiceTotal = dOrderTotal - dDiscountAmount
  21.                 lblDiscountAmount.Text = FormatNumber(dDiscountAmount)
  22.                 lblInvoiceTotal.Text = FormatNumber(dInvoiceTotal)
  23.             Else ' Out of range
  24.                 MessageBox.Show("Order total must be between " & _
  25.                 dMinOrderTotal & " and " & _
  26.                 dMaxOrderTotal & ".", "Entry error")
  27.             End If
  28.         Else
  29.             MessageBox.Show("You must enter a numeric value.", "Entry error")
  30.         End If
  31.         txtOrderTotal.Focus()
  32.  
  33.     End Sub
  34.  
  35.    
  36.     Public Function DiscountAmount(ByVal totalval As Decimal) As Decimal
  37.         Dim discount As Decimal
  38.         If totalval >= 500 Then
  39.             discount = 0.2
  40.         ElseIf totalval >= 250 Then
  41.             discount = 0.15
  42.         ElseIf totalval >= 100 Then
  43.             discount = 0.1
  44.         Else
  45.             discount = 0
  46.         End If
  47.         Dim DiscountAmt As Decimal = totalval * discount
  48.         Return DiscountAmt
  49.     End Function
  50.  
  51.  
  52.     Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
  53.         Me.Close()
  54.     End Sub