VBA for "In Play" timer

Please post any questions regarding the program here.

Moderator: 2020vision

VBA for "In Play" timer

Postby allgreen » Tue Apr 08, 2008 8:54 am

Hi all, could someone please help me with some VBA to record the time the race goes in play e.g. When E2 changes to "In Play" paste the value of C2 to W2.

I did find a small snippet of code which copied E2 when the race goes in play but this duplicates the timer in C2 and doesn't 'freeze' the race start time. I have played around with this trying for a special paste but couldn't get it to work.
allgreen
 
Posts: 98
Joined: Wed Mar 08, 2006 7:28 am
Location: Down Under

Postby PeteB » Tue Apr 08, 2008 9:26 am

There isn't a formula in C2, so if your destination cell keeps updating, it must be because your macro is running more than once.

So:
create a variable
Dim bGoneInPlay as boolean
and set it to true when you do the copy, and only do the copy if it is not already true. Remember to set it back to false when you load a new market.
PeteB
 
Posts: 258
Joined: Tue May 23, 2006 12:13 pm

Postby GaryRussell » Tue Apr 08, 2008 9:33 am

Insert the following code into sheet1

Private Sub Worksheet_Change(ByVal Target As Range)
If updating Then Exit Sub
updating = True
If cells(2, 5) = "In Play" Then
If cells(1, 27) = "" Then cells(1, 27) = cells(2, 3)
If cells(1, 27) <> "" Then cells(1, 28 ) = DateDiff("s", cells(1, 27), cells(2, 3))
End If
If cells(2, 5) <> "In Play" And cells(2, 6) <> "Suspended" Then
cells(1, 27) = ""
cells(1, 28 ) = ""
End If
updating = False
End Sub


Create a new module and add the following line.

Public updating As Boolean

Cell AA1 will contain the time the market went in play and cell AB1 will contain the number of seconds from when the market went in play.
User avatar
GaryRussell
Site Admin
 
Posts: 9708
Joined: Fri Nov 18, 2005 8:09 pm
Location: Birmingham, UK

Postby allgreen » Tue Apr 08, 2008 11:07 am

Thanks very much for the help Pete and Gary. And here was me expecting it was going to be something simple. I figure I would have still been trying to figure it out this time next year. :lol:

Gary, I put your code underneath some existing code which records a snapshot whenever my bets are updated and it has produced a compile error - 'Ambiguous name Detected : Worksheet_Change' - so evidently I need to combine these procedures or somehow define them? Needless to say I am a bit out of my depth here.

This is the existing code :


Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Columns.Count <> 16 Then Exit Sub '16 cols for the API version, 13 for the WEB version of the software.
Application.EnableEvents = False 'essential as any change will result in a possible endless loop and possible lock-up

Dim runners As Integer
Dim sourceRange As Range
Dim destRange As Range

Dim profitSource As Range
Dim profitDest As Range
Set profitSource = Range("X5:X28") 'presumably the range where your proit/loss appears
Set profitDest = Range("Y5:Y28") 'blank range that isn't used on your sheet CHANGE IF NEED BE


runners = WorksheetFunction.CountA(Range("A5:A40")) 'counts the current race runners, upto 36 runners


If WorksheetFunction.Sum(profitDest) <> WorksheetFunction.Sum(profitSource) Then 'identifies change and snapshots
Range("A45") = "Previous Snapshots"
Set sourceRange = Range(Cells(1, 1), Cells(1, 1).Offset(runners + 4, 120)) 'This is the current region used
Set destRange = Range((Cells(Rows.Count, "A").End(xlUp).Offset(6, 0)), Cells(Rows.Count, "A").End(xlUp).Offset(runners + 10, 120)) 'captures 100 columns
destRange.Value = sourceRange.Value
End If

profitDest.Value = profitSource.Value 'replaces old data with new updated data

Application.EnableEvents = True
End Sub
allgreen
 
Posts: 98
Joined: Wed Mar 08, 2006 7:28 am
Location: Down Under

Postby GaryRussell » Tue Apr 08, 2008 11:52 am

You are already using the change event so, just paste the following code before Application.EnableEvents = True. Also there is no need to create a module as the code you already have takes care of that part.

If cells(2, 5) = "In Play" Then
If cells(1, 27) = "" Then cells(1, 27) = cells(2, 3)
If cells(1, 27) <> "" Then cells(1, 28 ) = DateDiff("s", cells(1, 27), cells(2, 3))
End If
If cells(2, 5) <> "In Play" And cells(2, 6) <> "Suspended" Then
cells(1, 27) = ""
cells(1, 28 ) = ""
End If
User avatar
GaryRussell
Site Admin
 
Posts: 9708
Joined: Fri Nov 18, 2005 8:09 pm
Location: Birmingham, UK

Postby allgreen » Tue Apr 08, 2008 12:57 pm

Many thanks for your time Gary
allgreen
 
Posts: 98
Joined: Wed Mar 08, 2006 7:28 am
Location: Down Under

Postby xraymitch » Sat May 02, 2009 9:02 am

GaryRussell wrote:Insert the following code into sheet1

Private Sub Worksheet_Change(ByVal Target As Range)
If updating Then Exit Sub
updating = True
If cells(2, 5) = "In Play" Then
If cells(1, 27) = "" Then cells(1, 27) = cells(2, 3)
If cells(1, 27) <> "" Then cells(1, 28 ) = DateDiff("s", cells(1, 27), cells(2, 3))
End If
If cells(2, 5) <> "In Play" And cells(2, 6) <> "Suspended" Then
cells(1, 27) = ""
cells(1, 28 ) = ""
End If
updating = False
End Sub


Create a new module and add the following line.

Public updating As Boolean

Cell AA1 will contain the time the market went in play and cell AB1 will contain the number of seconds from when the market went in play.


Hi Gary,

At the moment I am using Version 1.1.0.50
Auto load quick pick on program start
Auto select market 1 minute before the off
and your timer code in sheet1.

All works very well except when race off times are delayed or race off times clash with each other etc, ending up with at least 2 to 3 races per day being skipped.

When you get a moment from programming (April release is awesome 8) ) can you help or point me in the right direction so that I can do the following:

I would prefer to
Load different venues in separate tab pages
and use your code in the separate sheets thus hopefully not skipping a race.

I briefly experimented with 3 sheets and inserted the appropriate line in each sheet.

Sheets("Sheet1").Select
Sheets("Sheet2").Select
Sheets("Sheet3").Select

Whilst this seemed to be checking the sheets it had the side effect of locking me out of Excel.

Cheers,

Ray :)
xraymitch
 
Posts: 410
Joined: Wed Jun 25, 2008 7:06 am
Location: UK

Postby sjaak1943 » Sat Mar 20, 2010 4:05 pm

GaryRussell wrote:Insert the following code into sheet1

Private Sub Worksheet_Change(ByVal Target As Range)
If updating Then Exit Sub
updating = True
If cells(2, 5) = "In Play" Then
If cells(1, 27) = "" Then cells(1, 27) = cells(2, 3)
If cells(1, 27) <> "" Then cells(1, 28 ) = DateDiff("s", cells(1, 27), cells(2, 3))
End If
If cells(2, 5) <> "In Play" And cells(2, 6) <> "Suspended" Then
cells(1, 27) = ""
cells(1, 28 ) = ""
End If
updating = False
End Sub


Create a new module and add the following line.

Public updating As Boolean

Cell AA1 will contain the time the market went in play and cell AB1 will contain the number of seconds from when the market went in play.


Can anyone tell me how to do this in my Excelsheet, step by step?
I don't know anything of macro's or modules!

Sjaak
sjaak1943
 
Posts: 174
Joined: Tue Oct 31, 2006 9:50 pm
Location: Schagen, the Netherlands

Postby osknows » Sat Mar 20, 2010 4:55 pm

In Excel 2003
1. Goto Tools/Options/Security/Macro Security and set macro security to medium
2. Close excel completely then re-open your workbook
3. Press Alt + F11 to get to the VBA editor
4. Double click the sheet name BA refreshes into on the left hand side of the VBA editor (eg Sheet1- it may be different if you have renamed it)
5. Copy the code Gary provided into the code window
6. Save your workbook, then link to BA

In Excel 2007
1. Goto Office Button/Excel Options/Trust Centre/Trust Centre Settings/MAcro Settings and set macro security 'Disable all macros with notification'
2. Close excel completely then re-open your workbook
3. Press Alt + F11 to get to the VBA editor
4. Double click the sheet name BA refreshes into on the left hand side of the VBA editor (eg Sheet1- it may be different if you have renamed it)
5. Copy the code Gary provided into the code window
6. Save your workbook, then link to BA
User avatar
osknows
 
Posts: 946
Joined: Wed Jul 29, 2009 12:01 am

Postby danjuma » Sat Mar 20, 2010 8:20 pm

osknows wrote:In Excel 2003
1. Goto Tools/Options/Security/Macro Security and set macro security to medium
2. Close excel completely then re-open your workbook
3. Press Alt + F11 to get to the VBA editor
4. Double click the sheet name BA refreshes into on the left hand side of the VBA editor (eg Sheet1- it may be different if you have renamed it)
5. Copy the code Gary provided into the code window
6. Save your workbook, then link to BA

In Excel 2007
1. Goto Office Button/Excel Options/Trust Centre/Trust Centre Settings/MAcro Settings and set macro security 'Disable all macros with notification'
2. Close excel completely then re-open your workbook
3. Press Alt + F11 to get to the VBA editor
4. Double click the sheet name BA refreshes into on the left hand side of the VBA editor (eg Sheet1- it may be different if you have renamed it)
5. Copy the code Gary provided into the code window
6. Save your workbook, then link to BA


Following on from osknows well explained step-by-step above, I think (if I am not wrong) the following bit below would have to be inserted in a module and not in your sheet. So from the VBA editor, click "Insert" from the tool bar and then "Module" and copy and paste the statement in bold below into the module.

Create a new module and add the following line.

Public updating As Boolean
User avatar
danjuma
 
Posts: 347
Joined: Mon Apr 21, 2008 4:17 pm

Postby sjaak1943 » Sat Mar 20, 2010 8:45 pm

Thanks Osknows.
Give it a try tomorrow!

Sjaak
sjaak1943
 
Posts: 174
Joined: Tue Oct 31, 2006 9:50 pm
Location: Schagen, the Netherlands

Postby osknows » Sun Mar 21, 2010 12:12 pm

Oh yes.. I didn't spot that bit :shock:

Danjuma is right, once you've taken my above steps then in the VBA editor

5a. Click Insert/Module
5b. Paste 'Public updating As Boolean' into the Module Code window
6. As above
User avatar
osknows
 
Posts: 946
Joined: Wed Jul 29, 2009 12:01 am

Postby sjaak1943 » Sun Mar 21, 2010 9:39 pm

I tried today without reading the forum.
It did not work properly. now I have read the forum, i give it a try tomorrow.

Thanks guys you're very helpfull.

What if I want to add another code in the sheet, f.i. extract race length?

Sjaak
sjaak1943
 
Posts: 174
Joined: Tue Oct 31, 2006 9:50 pm
Location: Schagen, the Netherlands

Postby osknows » Sun Mar 21, 2010 10:37 pm

Just add any additional code into the subroutine eg

Code: Select all
Private Sub Worksheet_Change(ByVal Target As Range)

'insert code to update quick pick list
'insert code to extract race length
'insert more....

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

Postby sjaak1943 » Mon Mar 22, 2010 9:05 am

Thanks Osknows, nice to have "this helpers" on the forum.

Sjaak
sjaak1943
 
Posts: 174
Joined: Tue Oct 31, 2006 9:50 pm
Location: Schagen, the Netherlands


Return to Help

Who is online

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

cron