Help calculating top 10 scores

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
BrianC
Newbie
Posts: 3
Joined: Thu Aug 31, 2006 11:48 am

Help calculating top 10 scores

Post by BrianC » Thu Aug 31, 2006 12:06 pm

First off great product!

Now to my question,
What I would like to do is have a script calculate for me which 10 numbers out of 80 different numbers have the best scores. For example lets say the number 1 has a score of 20 and numbers 2-80 have less than 20, that would make number 1 the best number.

Any help with this would be great and appreciated.

Thanks,
Brian C

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Thu Aug 31, 2006 1:31 pm

Hi Brian, welcome to the forum.

You're correct this is a great product.

First, have you made any attempts at writing any of this yourself? If you have, could you show us your work? If you have not, perhaps you should. The forum helps those who help themselves.

Second, In order to help you with coding it is necessary to know the format of the number scores. In other words, what does the text file that contains the information look like? Or is it not a text file? Is it in Excel? In a Data Base? etc.

Help us help you.

Later,
Dick

BrianC
Newbie
Posts: 3
Joined: Thu Aug 31, 2006 11:48 am

Post by BrianC » Thu Aug 31, 2006 1:58 pm

Hi Dick,

I have the scores saved to memory by using let>num1=num1+1 let>num2=num2+1 and so on.

I have tried the code below (times 80) but can't figure how to get the result for the top 10 numbers. :?

Code: Select all

if>{(%num1%>%num2%)and(%num1%>%num3%)and(%num1%>%num4%)and(%num1%>%num5%)and(%num1%>%num6%)and(%num1%>%num7%)and(%num1%>%num8%)and(%num1%>%num9%)and(%num1%>%num10%)and(%num1%>%num11%)and(%num1%>%num12%)and(%num1%>%num13%)and(%num1%>%num14%)and(%num1%>%num15%)and(%num1%>%num16%)and(%num1%>%num17%)and(%num1%>%num18%)and(%num1%>%num19%)and(%num1%>%num20%)and(%num1%>%num21%)and(%num1%>%num22%)and(%num1%>%num23%)and(%num1%>%num24%)and(%num1%>%num25%)and(%num1%>%num26%)and(%num1%>%num27%)and(%num1%>%num28%)and(%num1%>%num29%)and(%num1%>%num30%)and(%num1%>%num31%)and(%num1%>%num32%)and(%num1%>%num33%)and(%num1%>%num34%)and(%num1%>%num35%)and(%num1%>%num36%)and(%num1%>%num37%)and(%num1%>%num38%)and(%num1%>%num39%)and(%num1%>%num40%)and(%num1%>%num41%)and(%num1%>%num42%)and(%num1%>%num43%)and(%num1%>%num44%)and(%num1%>%num45%)and(%num1%>%num46%)and(%num1%>%num47%)and(%num1%>%num48%)and(%num1%>%num50%)and(%num1%>%num51%)and(%num1%>%num52%)and(%num1%>%num53%)and(%num1%>%num54%)and(%num1%>%num55%)and(%num1%>%num56%)and(%num1%>%num57%)and(%num1%>%num58%)and(%num1%>%num59%)and(%num1%>%num60%)and(%num1%>%num61%)and(%num1%>%num62%)and(%num1%>%num63%)and(%num1%>%num64%)and(%num1%>%num65%)and(%num1%>%num66%)and(%num1%>%num67%)and(%num1%>%num68%)and(%num1%>%num69%)and(%num1%>%num70%)and(%num1%>%num71%)and(%num1%>%num72%)and(%num1%>%num73%)and(%num1%>%num74%)and(%num1%>%num75%)and(%num1%>%num76%)and(%num1%>%num77%)and(%num1%>%num78%)and(%num1%>%num79%)and(%num1%>%num80%)}

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Thu Aug 31, 2006 2:40 pm

Your code doesn't seem to have much to do with your stated requirements. So I'm wondering if I've understood what you want to do correctly.

But it sounds like you have a list of numbers, each of which have a score. You want to sort the numbers by their scores to determine which are the highest scoring numbers. If I am right then you want a two dimensional array. First dimension is the numbers, second the scores. We then sort by the scores in descending order. Then we just real off the first 10 entries to get the 10 highest scoring numbers.

Easiest way to do that is in VBScript. Paste this into a new macro and run it:

Code: Select all

VBSTART

'set up the array
Dim myArray(12,1)

'first column - the numbers
myArray(0,0) = 1
myArray(1,0) = 2
myArray(2,0) = 3
myArray(3,0) = 4
myArray(4,0) = 5
myArray(5,0) = 6
myArray(6,0) = 7
myArray(7,0) = 8
myArray(8,0) = 9
myArray(9,0) = 10
myArray(10,0) = 11
myArray(11,0) = 12
myArray(12,0) = 13

'second column - the scores
myArray(0,1) = 32 'Num: 1
myArray(1,1) = 23 'Num: 2
myArray(2,1) = 64 'Num: 3
myArray(3,1) = 80 'Num: 4
myArray(4,1) = 8  'Num: 5
myArray(5,1) = 43 'Num: 6
myArray(6,1) = 56 'Num: 7
myArray(7,1) = 23 'Num: 8
myArray(8,1) = 84 'Num: 9
myArray(9,1) = 26 'Num: 10
myArray(10,1) = 11 'Num: 11
myArray(11,1) = 5 'Num: 12
myArray(12,1) = 55 'Num: 13

'sort myArray by column 2 in descending order
sortcol=1
For i = UBound(myArray)-2 To 0 Step -1
  For j = 0 to i
    If MyArray(j,sortcol)<MyArray(j+1,sortcol) then
      For m=0 to 1 'upper bound of dimensions
        temp=MyArray(j+1,m)
        MyArray(j+1,m) = MyArray(j,m)
        MyArray(j,m) = temp
      Next
    End if
  Next
Next

'so (0,0) now has highest scoring number; (1,0) next highest and so on ..
'so quick loop to display 10 highest scoring numbers
For k = 0 to 9
  MsgBox myArray(k,0)
Next

VBEND
Last edited by Marcus Tettmar on Thu Aug 31, 2006 2:52 pm, edited 1 time in total.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Thu Aug 31, 2006 2:48 pm

Marcus, how/where does that define the numbers as numbers so it's a numeric sort rather than an alpha sort (1, 10, 2, etc.) ?

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Thu Aug 31, 2006 2:50 pm

If MyArray(j,1)MyArray(j+1,1) then
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

BrianC
Newbie
Posts: 3
Joined: Thu Aug 31, 2006 11:48 am

Post by BrianC » Thu Aug 31, 2006 3:42 pm

Thank you Marcus! This is exactly what I had in mind :D

I have one last question. Since my scores change every few minutes and the script constantly loops and checks for changes in the scores how do I update the scores in the VB script.

The script below is only an example to make my self clear what I'm trying to do. Apparently MS script and VB script are not compatible and since I'm pretty new to Macro Scheduler I don’t know how to go by updating the scores in the VB script

Code: Select all

let>score1update=0
let>score2update=0
let>score3update=0
let>score4update=0
let>score5update=0
let>score6update=0
let>score7update=0
let>score8update=0
let>score9update=0
let>score10update=0
let>score11update=0
let>score12update=0
let>score13update=0

Label>LOOP
//IF SOMETHING HAPPENS CHECK WHICH SCORE HAS CHANGED
IF>SCORE1<PREVIEWS>score1update=score1update+1
ENDIF
IF>SCORE2<PREVIEWS>score2update=score2update+1
ENDIF
IF>SCORE3<PREVIEWS>score3update=score3update+1
ENDIF
IF>SCORE4<PREVIEWS>score4update=score4update+1
ENDIF
IF>SCORE5<PREVIEWS>score5update=score5update+1
ENDIF
IF>SCORE6<PREVIEWS>score6update=score6update+1
ENDIF
IF>SCORE7<PREVIEWS>score7update=score7update+1
ENDIF
IF>SCORE8<PREVIEWS>score8update=score8update+1
ENDIF
IF>SCORE9<PREVIEWS>score9update=score9update+1
ENDIF
IF>SCORE10<PREVIEWS>score10update=score10update+1
ENDIF
IF>SCORE11<PREVIEWS>score11update=score11update+1
ENDIF
IF>SCORE12<PREVIEWS>score12update=score12update+1
ENDIF
IF>SCORE13<PREVIEWS>score13update=score13update+1
ENDIF
//go VB Script
ENDIF
GoTo>LOOP
VBSTART
'set up the array
Dim myArray(12,1)
'first column - the numbers
myArray(0,0) = 1
myArray(1,0) = 2
myArray(2,0) = 3
myArray(3,0) = 4
myArray(4,0) = 5
myArray(5,0) = 6
myArray(6,0) = 7
myArray(7,0) = 8
myArray(8,0) = 9
myArray(9,0) = 10
myArray(10,0) = 11
myArray(11,0) = 12
myArray(12,0) = 13

'second column - the scores
myArray(0,1) = %score1update% 'Num: 1
myArray(1,1) = %score2update% 'Num: 2
myArray(2,1) = %score3update% 'Num: 3
myArray(3,1) = %score4update% 'Num: 4
myArray(4,1) = %score5update%  'Num: 5
myArray(5,1) = %score6update% 'Num: 6
myArray(6,1) = %score7update% 'Num: 7
myArray(7,1) = %score8update% 'Num: 8
myArray(8,1) = %score9update% 'Num: 9
myArray(9,1) = %score10update% 'Num: 10
myArray(10,1) = %score11update% 'Num: 11
myArray(11,1) = %score12update% 'Num: 12
myArray(12,1) = %score13update% 'Num: 13

'sort myArray by colum 2 in descending order
For i = UBound(myArray)-1 To 0 Step -1
  For j = 0 to i
    If MyArray(j,1)<MyArray>myArray(0,0),answer1
VBEval>myArray(1,0),answer2
VBEval>myArray(2,0),answer3
VBEval>myArray(3,0),answer4
VBEval>myArray(4,0),answer5
VBEval>myArray(5,0),answer6
VBEval>myArray(6,0),answer7
VBEval>myArray(7,0),answer8
VBEval>myArray(8,0),answer9
VBEval>myArray(9,0),answer10

MessageModal>%answer1%%CRLF%%answer2%%CRLF%%answer3%%CRLF%%answer4%%CRLF%%answer5%%CRLF%%answer6%%CRLF%%answer7%%CRLF%%answer8%%CRLF%%answer9%%CRLF%%answer10%

Thank you all so much for putting up with me and helping me out.

Brian

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Thu Aug 31, 2006 4:05 pm

Perhaps this will help:

Code: Select all

//Keep this VBSTART/VBEND block at TOP of script
VBSTART

'NumRows
const NumRows=12

'set up the array
Dim myArray(12,1)

'first column - the numbers
myArray(0,0) = 1
myArray(1,0) = 2
myArray(2,0) = 3
myArray(3,0) = 4
myArray(4,0) = 5
myArray(5,0) = 6
myArray(6,0) = 7
myArray(7,0) = 8
myArray(8,0) = 9
myArray(9,0) = 10
myArray(10,0) = 11
myArray(11,0) = 12
myArray(12,0) = 13

'second column - the scores
myArray(0,1) = 32 'Num: 1
myArray(1,1) = 23 'Num: 2
myArray(2,1) = 64 'Num: 3
myArray(3,1) = 80 'Num: 4
myArray(4,1) = 8  'Num: 5
myArray(5,1) = 43 'Num: 6
myArray(6,1) = 56 'Num: 7
myArray(7,1) = 23 'Num: 8
myArray(8,1) = 84 'Num: 9
myArray(9,1) = 26 'Num: 10
myArray(10,1) = 11 'Num: 11
myArray(11,1) = 5 'Num: 12
myArray(12,1) = 55 'Num: 13

Sub DoSort
  'sort myArray by column 2 in descending order
  sortcol=1
  For i = UBound(myArray)-2 To 0 Step -1
    For j = 0 to i
      If MyArray(j,sortcol)<MyArray(j+1,sortcol) then
        For m=0 to 1 'upper bound of dimensions
          temp=MyArray(j+1,m)
          MyArray(j+1,m) = MyArray(j,m)
          MyArray(j,m) = temp
        Next
      End if
    Next
  Next
End Sub

'Use this Sub to set a number's score
Sub SetScore(Num,Score)
  For k = 0 to NumRows
  	  if MyArray(k,0) = Num then
	  	 MyArray(k,1) = Score
	  End if
  Next
End Sub

VBEND

//Resort
VBRun>DoSort

//Output top 10 Scorers:
Let>k=0
Repeat>k
  VBEval>myArray(%k%,0),ThisNum
  MessageModal>ThisNum
  Let>k=k+1
Until>k=10

//We could modify the array here:
Let>k=0
Repeat>k
  //As an example I'll set the score to a random number
  Random>100,r
  VBRun>SetScore,k,r
  Let>k=k+1
until>k=13

//Now we could resort:
VBRun>DoSort

//Output 10 top scores again:
Let>k=0
Repeat>k
  VBEval>myArray(%k%,0),ThisNum
  VBEval>myArray(%k%,1),ThisScore
  MessageModal>%ThisNum% %ThisScore%
  Let>k=k+1
Until>k=10
In this version all the processing is controlled by MacroScript. We still use a VBScript array, but the sort code is now in a VBScript subroutine which we can call from MacroScript. I've also added a SetScore subroutine which can be called to set a number a new score. So you can call this when you need to change a score. In my example I give every number a new random score and then do the sort again and finally output the top 10 scoring numbers again (this time showing their scores).
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Thu Aug 31, 2006 4:35 pm

mtettmar wrote:If MyArray(j,1)MyArray(j+1,1) then
I think the answer I was looking for was that it's

myArray(0,1) = 32 not
myArray(0,1) = "32"

Sorry, but not having to quote strings in MacroScheduler always confuses me :oops:

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts