PC Review


Reply
Thread Tools Rate Thread

Comparison Operators

 
 
Carlo
Guest
Posts: n/a
 
      26th Feb 2004
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
 
Reply With Quote
 
 
 
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      26th Feb 2004
* (E-Mail 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.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet/>
 
Reply With Quote
 
EricJ
Guest
Posts: n/a
 
      26th Feb 2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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



 
Reply With Quote
 
Jay B. Harlow [MVP - Outlook]
Guest
Posts: n/a
 
      26th Feb 2004
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

"Carlo" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Comparison Operators =?Utf-8?B?RGV2YW5hdGggT25n?= Microsoft Excel Programming 2 22nd Jun 2006 03:16 PM
Comparison Operators J Jones Microsoft ADO .NET 4 24th Dec 2003 02:44 PM
Comparison Operators J Jones Microsoft VB .NET 2 24th Dec 2003 09:03 AM
Comparison Operators J Jones Microsoft ASP .NET 1 24th Dec 2003 01:17 AM
Re: DLOOKUP and comparison operators Richard Gurney Microsoft Access Queries 0 1st Aug 2003 07:45 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:18 AM.