Comparison Operators

  • Thread starter Thread starter Carlo
  • Start date Start date
C

Carlo

Hi
I need to average the two highest numerics entered in separate text
boxes using an if statement.

So far I have got

if txtFirst.Text >= txtSecond.text and txtFirst.Text >= txtThird.text
then
FirstHigh = txtFirst.text
elseif
txtSecond.Text >= txtFirst.text and txtSecond.Text >= txtThird.text
then
FirstHigh = txtSecond.text
elseif

txtThird.Text >= txtFirst.text and txtThird.Text >= txtSecond.text
then
FirstHigh = txtThird.text

This gives me which is the Highest. My problem is to get the second
highest value.

Please help

Carlob1
 
* (e-mail address removed) (Carlo) scripsit:
I need to average the two highest numerics entered in separate text
boxes using an if statement.

First, enable 'Option Explicit' and 'Option Strict'.

Then, convert the texts to numeric datatypes and add them to an
'ArrayList'. After doing that, call its 'Sort' method.
 
first i would suggest that you convert to numeric values before compairing
now you could end up w 99 being bigger then 100
2nd
try using an arraylist

like this
Dim int As New ArrayList

int.Add(CInt(txt1.text))

int.Add(CInt(txt2.text))
....
int.Sort()

Dim i As Integer = int.Count

intlargest = int(i - 1)

int2ndlargest = int(i - 2)

hope it helps

eric
 
Carlo,
I need to average the two highest numerics entered in separate text
boxes using an if statement.

Is the "if" statement a requirement (of the homework assignment?) or just
the only way you know how? As the Sort method the others pointed to is the
"easiest", alternatively you could use an insertion sort when you put the
values into the ArrayList, or simply use a SortedList.

If the "if" statement is a requirement:

Once you have the FirstHigh, to find the second you need to find the highest
text box (as before), that is lower then FirstHigh.

To find the third you need to find the highest text box (as before) that is
lower then the SecondHigh... and so on...

Hope this helps
Jay
 
Back
Top