race distance using macro

Please post any questions regarding the program here.

Moderator: 2020vision

race distance using macro

Postby alrodopial » Fri Jan 24, 2014 8:07 pm

There was some code (udf?) for extracting the dist (in furlongs) from text
ie from 2m3f110y

Any help?
alrodopial
 
Posts: 1355
Joined: Wed Dec 06, 2006 9:59 pm

Postby davez » Sat Jan 25, 2014 5:44 am

dont know if this is any help

=LEFT(A1,FIND("m",A1,1)-1)*8+MID(A1,FIND("f",A1,1)-1,1)+MID(A1,5,FIND("y",A1,1)-1-FIND("f",A1,1))*0.00454545455
davez
 
Posts: 77
Joined: Thu Jul 29, 2010 5:47 am

Postby alrodopial » Sat Jan 25, 2014 11:32 am

Thanks by I need a macro
alrodopial
 
Posts: 1355
Joined: Wed Dec 06, 2006 9:59 pm

Postby osknows » Sat Jan 25, 2014 12:17 pm

Code: Select all
Option Explicit

Sub test()
Dim distance As String
Dim furlongs As Double

    distance = "2m3f110y"
    furlongs = StringToFurlongs(distance)
   
End Sub

Function StringToFurlongs(ByVal dist As String) As Double
Dim dcmiles As Long
Dim dcfurlongs As Long
Dim dcyards As Long
       
        'miles
        If InStr(1, dist, "m") > 0 Then
            dcmiles = Left(dist, InStr(1, dist, "m") - 1)
        Else
            dcmiles = 0
        End If
       
        'furlongs
        If InStr(1, dist, "f") > 0 Then
        dcfurlongs = Mid(dist, InStr(1, dist, "m") + 1, InStr(1, dist, "f") - InStr(1, dist, "m") - 1)
        Else
        dcfurlongs = 0
        End If
       
        'yards (second test is for examples such as 1m100y where no furlongs in distance string)
        If InStr(1, dist, "y") > 0 Then
            If InStr(1, dist, "f") > 0 Then
                dcyards = Mid(dist, InStr(1, dist, "f") + 1, InStr(1, dist, "y") - InStr(1, dist, "f") - 1)
            Else
                dcyards = Mid(dist, InStr(1, dist, "m") + 1, InStr(1, dist, "y") - InStr(1, dist, "m") - 1)
            End If
        Else
            dcyards = 0
        End If
       

        StringToFurlongs = (dcmiles * 8) + dcfurlongs + (dcyards / 220)
       
End Function
User avatar
osknows
 
Posts: 946
Joined: Wed Jul 29, 2009 12:01 am

Postby alrodopial » Sat Jan 25, 2014 4:23 pm

Thats it,
thanks Os
alrodopial
 
Posts: 1355
Joined: Wed Dec 06, 2006 9:59 pm

Postby mak » Sat Jan 25, 2014 4:33 pm

Al exeis pm
mak
 
Posts: 1086
Joined: Tue Jun 30, 2009 8:17 am

Postby alrodopial » Sun Jan 26, 2014 12:40 pm

I changed the code a bit to include the case: 1f100y - no miles in string

Code: Select all
Public Function StringToFurlongs(ByVal dist As String) As Double
   
    Dim dcmiles As Long
    Dim dcfurlongs As Long
    Dim dcyards As Long
   
    'miles
    If InStr(1, dist, "m") > 0 Then
        dcmiles = Left(dist, InStr(1, dist, "m") - 1)
    Else
        dcmiles = 0
    End If
   
    'furlongs (second test is for examples such as 1f100y where no miles in distance string)
    If InStr(1, dist, "f") > 0 Then
        If InStr(1, dist, "m") > 0 Then
            dcfurlongs = Mid(dist, InStr(1, dist, "m") + 1, InStr(1, dist, "f") - InStr(1, dist, "m") - 1)
        Else
            dcfurlongs = Left(dist, InStr(1, dist, "f") - 1)
        End If
    Else
        dcfurlongs = 0
    End If
   
    'yards (second test is for examples such as 1m100y where no furlongs in distance string)
    If InStr(1, dist, "y") > 0 Then
        If InStr(1, dist, "f") > 0 Then
            dcyards = Mid(dist, InStr(1, dist, "f") + 1, InStr(1, dist, "y") - InStr(1, dist, "f") - 1)
        Else
            dcyards = Mid(dist, InStr(1, dist, "m") + 1, InStr(1, dist, "y") - InStr(1, dist, "m") - 1)
        End If
    Else
        dcyards = 0
    End If
   
    StringToFurlongs = (dcmiles * 8) + dcfurlongs + Round((dcyards / 220), 2)
   
End Function


Thanks again Os
alrodopial
 
Posts: 1355
Joined: Wed Dec 06, 2006 9:59 pm

Re: race distance using macro

Postby vanbuuts » Sat May 23, 2015 9:08 pm

Hi, how does this macro run and where does it put the distance?

Also, the formula higher up the thread doesn't seem to work
vanbuuts
 
Posts: 321
Joined: Thu Oct 16, 2014 8:55 pm

Re: race distance using macro

Postby Captain Sensible » Mon May 25, 2015 2:11 pm

It runs the same as other Functions like minusTicks or plusTicks, you'd just enter the value you wanted converted in StringToFurlongs() either in your other macros or in excel like =stringtofurlongs("5f") or if the cell you wanted converting is A1 =stringtofurlongs(A1) .

It's just converting the distance not extracting it from A1, so you'd need to do that separately. I think it was written to parse the Racing Post or other external distances rather than converting A1
User avatar
Captain Sensible
 
Posts: 2883
Joined: Sat Nov 19, 2005 2:29 pm

Re: race distance using macro

Postby dflowe » Sat Oct 24, 2020 4:21 pm

the code for the excel cell don't work either, maybe something changed in the a1 cell?
Dave
dflowe
 
Posts: 173
Joined: Sat Dec 31, 2005 11:41 am
Location: Midlands

Re: race distance using macro

Postby Captain Sensible » Sat Oct 24, 2020 4:51 pm

Works OK for me, your excel code was just splitting at the ":" so should pick out the distance for all races except the To be placed ones. You could always tweak the function slightly to remove your excel formula
User avatar
Captain Sensible
 
Posts: 2883
Joined: Sat Nov 19, 2005 2:29 pm

Re: race distance using macro

Postby dflowe » Sat Oct 24, 2020 5:37 pm

Sorry I am lost now, is it this 1 that works:-
=IF(TYPE(FIND("m",AA1))=16,LEFT(AA1,LEN(AA1)-FIND("f",AA1)+1)*1,IF(TYPE(FIND("f",AA1))=16,LEFT(AA1,LEN(AA1)-FIND("m",AA1)+1)*8,LEFT(AA1,FIND("m",AA1)-1)*8+MID(AA1,FIND("m",AA1)+1,FIND("f",AA1)-FIND("m",AA1)*1-1)))
where AA! is the result of:-
IF(MID(A1,FIND(":",A1)+6,1)="",MID(A1,FIND(":",A1)+4,2),MID(A1,FIND(":",A1)+4,3)) giving result in form 3m4, 2m, 7f etc

or is it this 1:-
=LEFT(A1,FIND("m",A1,1)-1)*8+MID(A1,FIND("f",A1,1)-1,1)+MID(A1,5,FIND("y",A1,1)-1-FIND("f",A1,1))*0.00454545455

as i cant get either to work and if there is a correction to make could you please indicate where as I dont see a ":" in either,
sorry not that good with excel, can do basic maths LOL LOL

thanks Dave
dflowe
 
Posts: 173
Joined: Sat Dec 31, 2005 11:41 am
Location: Midlands

Re: race distance using macro

Postby Captain Sensible » Sat Oct 24, 2020 5:40 pm

I meant in your excel formula to pick out the distance from the race details in A1. I thought you'd use the Function rather than some long excel formula as it's a lot easier ad could be tweaked to pick out the distance from A1
User avatar
Captain Sensible
 
Posts: 2883
Joined: Sat Nov 19, 2005 2:29 pm

Re: race distance using macro

Postby Captain Sensible » Sat Oct 24, 2020 5:44 pm

Here's a tweaked version of Osknows code so you can simply extract the distance from the A1 string and convert to furlongs. You just use it within any VBA code you use or simply stick this formula in whatever cell you need

Code: Select all
=StringToFurlongs(A1)



The VBA function is as below and you'd just need to add it to a module. https://www.ablebits.com/office-addins- ... cro-excel/
Code: Select all

 Public Function StringToFurlongs(ByVal dist As String) As Double
 
 If InStr(1, dist, ":") > 0 Then
 Dim marketArray() As String
 marketArray = Split(dist, ":")
 dist = Split(marketArray(1), " ")(1)
 Else
 StringToFurlongs = 0
 Exit Function
 End If

       
        Dim dcmiles As Long
        Dim dcfurlongs As Long
        Dim dcyards As Long
       
        'miles
        If InStr(1, dist, "m") > 0 Then
            dcmiles = Left(dist, InStr(1, dist, "m") - 1)
        Else
            dcmiles = 0
        End If
       
       
        If InStr(1, dist, "f") > 0 Then
            If InStr(1, dist, "m") > 0 Then
                dcfurlongs = Mid(dist, InStr(1, dist, "m") + 1, InStr(1, dist, "f") - InStr(1, dist, "m") - 1)
            Else
                dcfurlongs = Left(dist, InStr(1, dist, "f") - 1)
            End If
        Else
            dcfurlongs = 0
        End If
       
         StringToFurlongs = (dcmiles * 8) + dcfurlongs
       
   
    End Function
User avatar
Captain Sensible
 
Posts: 2883
Joined: Sat Nov 19, 2005 2:29 pm


Return to Help

Who is online

Users browsing this forum: No registered users and 25 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.