Helpwith VBA code.

Please post any questions regarding the program here.

Moderator: 2020vision

Helpwith VBA code.

Postby Bassdrinker » Tue Nov 18, 2025 10:25 pm

Code: Select all
Sub countDown()
    MsgBox ("Sub countdown called ")
    countDownComplete = False
    While countDownComplete = False
        countDownValue = Range("D2")
        hours = Left$(countDownValue, 2)
        minutes = Mid$(countDownValue, 4, 2)
        Seconds = Right$(countDownValue, 2)
        totalSeconds = (hours * 3600)
        totalSeconds = totalSeconds + (minutes * 60)
        totalSeconds = totalSeconds + (Seconds)
        MsgBox (hours & " " & minutes & " " & Seconds & " " & totalSeconds)
        If totalSeconds < 5 Then countDownCompleted = True
        Range("T1") = totalSeconds
    Wend
End Sub


Can anyone please help with the above vba code that I am trying to run using Excel 2007?

The idea is simple enough.

Set countdowncomplete to False
While countdowncomplete=Fallse
Read the time left from cell D2
Split the string into hours, minutes and seconds.
Convert hours, minutes and seconds into totalseconds
OPTION - Print totalseconds as a messagebox
if totalseconds is <5 then set countdowncomplete to true
End while loop

There is some odd behaviour that I don't understand. If I run the sub as above it appears to work perfectly although each iteration stops with a messagebox that needs to be clicked. However, if I comment out the call to the messagebox the sheet freezes as though it were being overloaded by the data from GBA.

Has anyone experienced this before?

TIA

Bassdrinker
Bassdrinker
 
Posts: 18
Joined: Sun Jan 12, 2020 2:57 pm

Re: Helpwith VBA code.

Postby GaryRussell » Wed Nov 19, 2025 10:34 am

The count down is running in a tight loop which will use a lot of CPU and while VBA code is running Excel cannot be updated by Betting Assistant.

It is better to avoid a loop and use a timer instead. Put the following code in a module. It calls itself every second using Application.OnTime which allows Excel to continue it's usual processing during each second it is waiting. It is far more CPU efficient.

Code: Select all
Sub countDown()
    'MsgBox ("Sub countdown called ")
    countDownComplete = False
    countDownValue = Sheets("Sheet1").Range("D2").Text
    hours = Left$(countDownValue, 2)
    minutes = Mid$(countDownValue, 4, 2)
    Seconds = Right$(countDownValue, 2)
    totalSeconds = (hours * 3600)
    totalSeconds = totalSeconds + (minutes * 60)
    totalSeconds = totalSeconds + (Seconds)
    'MsgBox (hours & " " & minutes & " " & Seconds & " " & totalSeconds)
    If totalSeconds < 5 Then countDownComplete = True
    Application.EnableEvents = False
    Range("T1") = totalSeconds
    Debug.Print totalSeconds
    Application.EnableEvents = True
    If Not countDownComplete Then
        Application.OnTime Now + TimeValue("00:00:01"), "countDown"
    Else
        'Do something after count down complete
    End If
End Sub
User avatar
GaryRussell
Site Admin
 
Posts: 9946
Joined: Fri Nov 18, 2005 8:09 pm
Location: Birmingham, UK

Re: Helpwith VBA code.

Postby Bassdrinker » Wed Nov 19, 2025 11:28 am

while VBA code is running Excel cannot be updated by Betting Assistant.


Ahh, that explains everything. Thanks for your help. Will, implement it later.

Much appreciated.

Bd
Bassdrinker
 
Posts: 18
Joined: Sun Jan 12, 2020 2:57 pm


Return to Help

Who is online

Users browsing this forum: TBMsupport and 41 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.