VBA/COM optimisation

Please post any questions regarding the program here.

Moderator: 2020vision

VBA/COM optimisation

Postby Spike » Tue Mar 22, 2011 4:50 pm

Hello helpful VBA bods - I have a question.

I'm getting an array full of prices using using:

prices = ba.getPrices

Then I loop through that to do my thing - only I'm always trying to cut down the number of loops I do.
Is there any way I can quickly get the following information from the prices array without looping through it?

1: The selection name of the 1st selection on the list.

2: The lowest value in the best available back-price column.
2b: The "row" address of that value

Thanks!
Spike
 
Posts: 223
Joined: Tue Feb 24, 2009 8:42 pm

Postby osknows » Tue Mar 22, 2011 8:32 pm

Hi Spike,

What TYPE is 'prices'? Is it a standard array, a collection or a class collection?

Also do you know if it's sorted or indexed?

If you could post or PM an example of the type and what's contained within it I may be able to help.

Unfortunately I've never been able to get the COM reference to work on my computer and haven't really chased it up as I don't need to use it so can't check the variable type myself. (I get exactly the same issue as Here
User avatar
osknows
 
Posts: 946
Joined: Wed Jul 29, 2009 12:01 am

Postby GaryRussell » Wed Mar 23, 2011 11:46 am

getPrices() returns an array so you can access the first item by reading index 0.

eg.
Code: Select all
prices = ba.getPrices()
firstPriceItem = prices(0)


BA does not calculate the lowest prices for you so you will need to loop through to find this unfortunately. It's not sorted or indexed.
User avatar
GaryRussell
Site Admin
 
Posts: 9872
Joined: Fri Nov 18, 2005 8:09 pm
Location: Birmingham, UK

Re: VBA/COM optimisation

Postby osknows » Wed Mar 23, 2011 3:21 pm

Spike wrote:1: The selection name of the 1st selection on the list.

2: The lowest value in the best available back-price column.
2b: The "row" address of that value

Thanks!


There are 4 methods I know of for search arrays in VBA but it depends on the size of the array and I'd guess that order is also important in context of BA so 1. and 2. are probably not applicable.

1. Copy to excel sheet first and search using Range/Find method
2. Sort the array from highest value to lowest then use Lbound and Ubound to find the max and min
3. Loop the array
4. Use Excel Worksheet functions

The following records the number of ticks for 3. & 4. for each of your questions above using a fictitious array 'strArray = .Range("A1:F17").Value'

Code: Select all
Public Declare PtrSafe Function GetTickCount Lib "kernel32" () As Long

Sub test()

With Sheet1

strArray = .Range("A1:F17").Value

'1st name in array
strname = strArray(LBound(strArray), 1) 'may need to change 1 if name is not first column element

'Find Min - loop method (min in second column element)
tickStart = GetTickCount
LMin = strArray(1, 2)
For i = LBound(strArray) To UBound(strArray)
    If strArray(i, 2) < LMin Then
        LMin = strArray(i, 2)
        LRow = i
    End If
   
Next i
tickLoop = GetTickCount - tickStart

'Find Min - function method (min in second column element)
tickStart = GetTickCount
FMin = Application.WorksheetFunction.Min(Application.WorksheetFunction.Index(strArray, 0, 2))
FRow = Application.WorksheetFunction.Match(FMin, Application.WorksheetFunction.Index(strArray, 0, 2), 0)
tickFunction = GetTickCount - tickStart


MsgBox ("First Name: " & strname & Chr(10) & "Loop Method - " & tickLoop & " ticks, Min = " & _
LMin & " Row = " & LRow & Chr(10) & "Excel Function Method - " & tickFunction & " ticks, Min = " & _
FMin & " Row = " & FRow)

End With
End Sub
User avatar
osknows
 
Posts: 946
Joined: Wed Jul 29, 2009 12:01 am

Postby Spike » Wed Mar 23, 2011 3:59 pm

Thanks chaps - that's excellent.

I love this forum.
Spike
 
Posts: 223
Joined: Tue Feb 24, 2009 8:42 pm


Return to Help

Who is online

Users browsing this forum: No registered users and 59 guests

Sports betting software from Gruss Software


The strength of Gruss Software is that it’s been designed by one of you, a frustrated sports punter, and then developed by listening to dozens of like-minded enthusiasts.

Gruss is owned and run by brothers Gary and Mark Russell. Gary discovered Betfair in 2004 and soon realised that using bespoke software to place bets was much more efficient than merely placing them through the website.

Gary built his own software and then enhanced its features after trialling it through other Betfair users and reacting to their improvement ideas, something that still happens today.

He started making a small monthly charge so he could work on it full-time and then recruited Mark to help develop the products and Gruss Software was born.

We think it’s the best of its kind and so do a lot of our customers. But you can never stand still in this game and we’ll continue to improve the software if any more great ideas emerge.