Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27346

Final attempt.... HELP what am i doing wrong?

$
0
0
I need to write an application that allows the user to enter three Double values, then determines and
displays the smallest and largest values.

Using functions to get s Minimum and Maximum that each receive three Double values and return a Double result and by using the math.min math.max.

I also need to do input verification so only numbers can be entered and not a string.

What am I doing wrong now!!!????

vb Code:
  1. Option Strict On
  2. Public Class HighestLowest
  3.  
  4.  
  5.     ' code pseoudo
  6.     ' INPUT 3 numbers
  7.     ' pass to function lowest
  8.     ' return lowest DISPLAY lowest
  9.     ' pass to function highest
  10.     ' return highest DISPLAY highest
  11.  
  12.     ' global vars
  13.     Dim oneNum As Double = 0
  14.     Dim twoNum As Double = 0
  15.     Dim threeNum As Double = 0
  16.     Dim highNum As Double
  17.     Dim lowNum As Double
  18.  
  19.     Private Sub submitBtn_Click(sender As Object, e As EventArgs) Handles submitBtn.Click
  20.  
  21.         ' verify that the input is a number
  22.         If IsNumeric(input1Tbx.Text) = True Then
  23.             oneNum = CDbl(input1Tbx.Text)
  24.        ElseIf : MessageBox.Show("Please enter numbers only.", "Please check your input values.", MessageBoxButtons.OK, MessageBoxIcon.Error)
  25.             input1Tbx.Text = ""
  26.             input2Tbx.Text = ""
  27.             input3Tbx.Text = ""
  28.             input1Tbx.Focus()
  29.             Exit Sub
  30.             If IsNumeric(input2Tbx.Text) = True Then
  31.                 twoNum = CDbl(input2Tbx.Text)
  32.             ElseIf : MessageBox.Show("Please enter numbers only.", "Please check your input values.", MessageBoxButtons.OK, MessageBoxIcon.Error)
  33.                 input1Tbx.Text = ""
  34.                 input2Tbx.Text = ""
  35.                 input3Tbx.Text = ""
  36.                 input1Tbx.Focus()
  37.                 Exit Sub
  38.                 If IsNumeric(input3Tbx.Text) = True Then
  39.                     threeNum = CDbl(input3Tbx.Text)
  40.                 ElseIf : MessageBox.Show("Please enter numbers only.", "Please check your input values.", MessageBoxButtons.OK, MessageBoxIcon.Error)
  41.                     input1Tbx.Text = ""
  42.                     input2Tbx.Text = ""
  43.                     input3Tbx.Text = ""
  44.                     input1Tbx.Focus()
  45.                     Exit Sub
  46.                 End If
  47.             End If
  48.         End If
  49.  
  50.  
  51.         highNum = largest(oneNum, twoNum, threeNum)
  52.         largestLbl.Text = highNum.ToString
  53.  
  54.         lowNum = smallest(oneNum, twoNum, threeNum)
  55.         smallestLbl.Text = lowNum.ToString
  56.  
  57.  
  58.     End Sub
  59.  
  60.     Function largest(ByVal one As Double, ByVal two As Double, ByVal three As Double) As Double
  61.  
  62.         Dim tempMax As Double
  63.         Dim finalMax As Double
  64.  
  65.         tempMax = Math.Max(one, two)
  66.         finalMax = Math.Max(tempMax, three)
  67.  
  68.         Return finalMax
  69.  
  70.     End Function ' Maximum
  71.  
  72.     Function smallest(ByVal one As Double, ByVal two As Double, ByVal three As Double) As Double
  73.  
  74.         Dim tempMin As Double
  75.         Dim finalMin As Double
  76.  
  77.         tempMin = Math.Min(one, two)
  78.         finalMin = Math.Min(tempMin, three)
  79.  
  80.         Return finalMin
  81.  
  82.     End Function ' Minimum
  83. End Class

I am not getting the validation to work... where is my error??

Viewing all articles
Browse latest Browse all 27346

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>