Auto Update Macro

Discuss anything related to using the program (eg. triggered betting tactics)

Moderator: 2020vision

Auto Update Macro

Postby Shaun » Tue Feb 28, 2012 1:24 am

I need a macro to run every 30 seconds and wanted to find the best option.

There is plenty of info about Application.OnTime on the net but i was wondering if this is the best option considering we already have the betfair feed updating.

Suggestions please.
Shaun
 
Posts: 435
Joined: Fri May 09, 2008 11:11 pm
Location: Kellerberrin, Western Australia

Postby faibo » Tue Feb 28, 2012 2:32 am

Consider using the Worksheet_change sub of a worksheet object.

http://www.gruss-software.co.uk/forum/v ... php?t=6547

If can also use the "Private Sub ba_pricesUpdated()" as stated in the help file.

Application.OnTime would work but i recommend the use of Worksheet/workbook change
User avatar
faibo
 
Posts: 23
Joined: Sun Sep 18, 2011 9:02 pm

Postby Shaun » Tue Feb 28, 2012 3:44 am

yes i understand now, design a counter and have my macro run when it is higher then say 30 and have the counter reset to zero.

Thanks.
Shaun
 
Posts: 435
Joined: Fri May 09, 2008 11:11 pm
Location: Kellerberrin, Western Australia

Postby faibo » Tue Feb 28, 2012 4:13 am

Well, I dont know your case. Maybe you can elaborate, but that doesnt seems to be the best solution.

if you want to use .Ontime you just need to run this:


Code: Select all
dTime = Now + TimeValue("00:00:30")
Application.OnTime dTime, "MyMacro"


If you put it at the end of your macro it will be called every 30seconds. You just need to call your macro one time, then it will run auto.
You dont need any counter

I dont know if that's a fit for your code. I'm just guessing. You can PM me if you want to elaborate
User avatar
faibo
 
Posts: 23
Joined: Sun Sep 18, 2011 9:02 pm

Postby Shaun » Tue Feb 28, 2012 4:33 am

Can you look at this macro and see if there is an issue?

The timer part works ok but the bottom half of my macro that used to work has stop working.

Code: Select all
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Columns.Count <> 16 Then Exit Sub
Application.EnableEvents = False
With ThisWorkbook
.Sheets("Data").Range("R1").Value = .Sheets("Data").Range("R1").Value + 1
If .Sheets("Control").Range("S5").Value = 0 Then
.Sheets("Data").Range("R1").Value = 0
GoTo Xit:
Else
If .Sheets("Data").Range("R1").Value > .Sheets("Control").Range("S5").Value Then
.Sheets("Data").Range("R1").Value = 1
BetChoice
Xit:
End If
End If
If .Sheets("Data").Range("T2").Value <> 1 Then
   .Sheets("Data").Range("T3").Value = 0
End If
If .Sheets("Data").Range("T2").Value = 1 And .Sheets("Data").Range("T3").Value <> 1 Then
    Paste1
   .Sheets("Data").Range("T3").Value = 1
End If

If .Sheets("Data").Range("U2").Value <> 1 Then
   .Sheets("Data").Range("U3").Value = 0
End If
If .Sheets("Data").Range("U2").Value = 1 And .Sheets("Data").Range("U3").Value <> 1 Then
  Result
   .Sheets("Data").Range("U3").Value = 1
End If

Application.EnableEvents = True
End With
End Sub


Here is the original macro that used to work fine.

Code: Select all
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Columns.Count <> 16 Then Exit Sub
Application.EnableEvents = False
With ThisWorkbook
If .Sheets("Data").Range("T2").Value <> 1 Then
   .Sheets("Data").Range("T3").Value = 0
End If
If .Sheets("Data").Range("T2").Value = 1 And .Sheets("Data").Range("T3").Value <> 1 Then
    Paste1
   .Sheets("Data").Range("T3").Value = 1
End If

If .Sheets("Data").Range("U2").Value <> 1 Then
   .Sheets("Data").Range("U3").Value = 0
End If
If .Sheets("Data").Range("U2").Value = 1 And .Sheets("Data").Range("U3").Value <> 1 Then
  Result
   .Sheets("Data").Range("U3").Value = 1
End If

Application.EnableEvents = True
End With
End Sub
Shaun
 
Posts: 435
Joined: Fri May 09, 2008 11:11 pm
Location: Kellerberrin, Western Australia

Postby Shaun » Tue Feb 28, 2012 8:19 am

I changed the code, not tested yet but i think should be ok.
Code: Select all

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Columns.Count <> 16 Then Exit Sub
Application.EnableEvents = False
With ThisWorkbook
.Sheets("Data").Range("R1").Value = .Sheets("Data").Range("R1").Value + 1
If .Sheets("Control").Range("S5").Value = 0 Then
   .Sheets("Data").Range("R1").Value = 0
End If
If .Sheets("Data").Range("R1").Value > .Sheets("Control").Range("S5").Value Then
   .Sheets("Data").Range("R1").Value = 1
   BetChoice
End If

If .Sheets("Data").Range("T2").Value <> 1 Then
   .Sheets("Data").Range("T3").Value = 0
End If
If .Sheets("Data").Range("T2").Value = 1 And .Sheets("Data").Range("T3").Value <> 1 Then
    Paste1
   .Sheets("Data").Range("T3").Value = 1
End If

If .Sheets("Data").Range("U2").Value <> 1 Then
   .Sheets("Data").Range("U3").Value = 0
End If
If .Sheets("Data").Range("U2").Value = 1 And .Sheets("Data").Range("U3").Value <> 1 Then
  Result
   .Sheets("Data").Range("U3").Value = 1
End If

Application.EnableEvents = True
End With
End Sub
Shaun
 
Posts: 435
Joined: Fri May 09, 2008 11:11 pm
Location: Kellerberrin, Western Australia

Postby osknows » Tue Feb 28, 2012 12:50 pm

You may find the DateDiff function useful down to 1 second accuracy. If you need ms accuracy lookup 'vb timer class' in a search engine.
User avatar
osknows
 
Posts: 946
Joined: Wed Jul 29, 2009 12:01 am

Postby Shaun » Tue Feb 28, 2012 6:13 pm

Thanks, don't need it that accurate as i am importing webpages just need it to run.
Shaun
 
Posts: 435
Joined: Fri May 09, 2008 11:11 pm
Location: Kellerberrin, Western Australia

Postby Shaun » Tue Feb 28, 2012 6:26 pm

You can answer a question for me if that;s ok?

I have 6 macros to run that each import bookmakers prices, would i be better off running all the macros at once or have them in a sequence where at the end of each macro it will call the next macro and so on until all have run.

Right now they are in a sequence and it takes about 10 seconds to run all 6 this time is fine for me but just wondering the best option.
Shaun
 
Posts: 435
Joined: Fri May 09, 2008 11:11 pm
Location: Kellerberrin, Western Australia

Postby faibo » Tue Feb 28, 2012 7:31 pm

All code in vba run in sequence. single threading.

So, your 2 options are basically the same.

If you want faster times you can look here:
http://www.excelhero.com/blog/2010/05/multi-threaded-vba-update.html
User avatar
faibo
 
Posts: 23
Joined: Sun Sep 18, 2011 9:02 pm

Postby Shaun » Wed Feb 29, 2012 1:24 am

Gees that swam looks interesting in deed, i do a hell of a lot of scraping for almost every sheet i create.

I can see i won't understand a lot of this so will be asking for help in time,hehe.
Shaun
 
Posts: 435
Joined: Fri May 09, 2008 11:11 pm
Location: Kellerberrin, Western Australia


Return to Discussion

Who is online

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