VB question #3

Charlie

Board Regular
Joined
Mar 1, 2002
Messages
134
If I was building an APP to accept 3 soccer results from a user,how would I code it to display the two highest scores and the average of the highest two scores.
I have tried this but as usual everything works but the scores are wrong and I dont get the average.
So mines pretty much useless.

Thanks
Charlie


Private Sub cmdStart_Click()
'Declare required storage
Dim Home As Integer
Dim Away As Integer
Dim Draw As Integer

'Invite user to input scores
Home = InputBox("Please input first score ", "Score 1")
Away = InputBox("Please input second score ", "Score 2")
Draw = InputBox("Please input third score ", "Score 3")

If Home > Away Then
picMessage.Print "The highest scores are "; (Home)
ElseIf Away > Home Then
picMessage.Print "The highest scores are "; (Away)
Else
picMessage.Print "The highest scores are "; (Draw)
End If
This message was edited by Charlie on 2002-10-17 19:12
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
On 2002-10-17 18:39, Charlie wrote:
If I was building an APP to accept 3 soccer results from a user,how would I code it to display the two highest scores and the average of the highest two scores.
I have tried this but as usual everything works but the scores are wrong and I dont get the average.
So mines pretty much useless.

Thanks
Charlie


Private Sub cmdStart_Click()
'Declare required storage
Dim Home As Integer
Dim Away As Integer
Dim Draw As Integer

'Invite user to input scores
Home = InputBox("Please input first score ", "Score 1")
Away = InputBox("Please input second score ", "Score 2")
Draw = InputBox("Please input third score ", "Score 3")

If Home > Away Then
picMessage.Print "The highest scores are "; (Home)
ElseIf Away > Home Then
picMessage.Print "The highest scores are "; (Away)
Else
picMessage.Print "The highest scores are "; (Draw)
End If
This message was edited by Charlie on 2002-10-17 19:12

See if this helps you at all:

Dim Score1 as Integer
Dim Score2 as Integer
Dim Score3 as Integer

Score1 = InputBox("Please enter your first score.")
Score2 = InputBox("Please enter your second score.")
Score3 = InputBox("Please enter your third score.")
MsgBox "The average score is: "&val((Score1+Score2+Score3)/3)
 
Upvote 0
Thanks but I dont think that will work.I see no code to give the highest two scores.
Then I need the average of these two highest scores not the average of all three.
If im wrong blow my head off but for once I think im right here.

Charlie
 
Upvote 0
There are Excel functions that can give you both results required without resorting to VBA

=Large(array,k) will give you the kth largest value in the array

so =LARGE({3,4,5},1) equals 5
so =LARGE({3,4,5},2) equals 4

=Average(4,5) equals 4.5

You could use an Inputbox statement to enter the values supplied by the user into spreadsheet cells with the functions in other cells to compute the results.
Alternatively, you may be able to use these functions directly within VBA (but not all Excel functions can be used in VBA)

HTH
BigC
 
Upvote 0
Thanks for that answer.But that would be for Excel and not VB6 which is what my question is about.
Im sorry for the confusion.
Charlie

I now have the answer I was looking for although I would have preferred it coded simpler.
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,716
Members
448,985
Latest member
chocbudda

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top