To return the result of your Function you need to set the Functions return value:
Function GameTimer(FirstStarted, SecondStarted, GameType)
...
GameTimer = 90
End Function
Your GameTimer Function should look something like this:
Function GameTimer(FirstStarted, SecondStarted, GameType)
Dim result
result = 90
If GameType = "Soccer" Then
DateFirstStarted = DateDiff("n", FirstStarted, FormatDateTime(Now(), 0))
DateSecondStarted = DateDiff("n", SecondStarted, FormatDateTime(Now(), 0))
If DateFirstStarted <= 45 Then
result = DateFirstStarted
End If
If DateSecondStarted <= 45 Then
result = DateSecondStarted + 45
End If
End If
GameTimer = result
End Function
This would work, but it's still not clean code.
First, you should get rid of the GameType because what you actually want, is to determine the length of a period:
Function GameTimer(FirstStarted, SecondStarted, PeriodInMinutes)
Dim result
result = PeriodInMinutes * 2
DateFirstStarted = DateDiff("n", FirstStarted, FormatDateTime(Now(), 0))
DateSecondStarted = DateDiff("n", SecondStarted, FormatDateTime(Now(), 0))
If DateFirstStarted <= PeriodInMinutes Then
result = DateFirstStarted
End If
If DateSecondStarted <= PeriodInMinutes Then
result = DateSecondStarted + PeriodInMinutes
End If
GameTimer = result
End Function
Usage
CurrentGameTime = GameTimer(FormatDateTime(objLiveCommentary("DateFirstStarted"), 0),
FormatDateTime(objLiveCommentary("DateSecondStarted"), 0),
45)
A next step would be to replace the parameters FirstStarted and SecondStarted by an Array to allow games with thirds and quarters.
Array of period start times
Function GameTimer(Periods, PeriodInMinutes)
Dim result
Dim currenttime
Dim i
result = 0 '-- preset to zero --'
For i = 1 To (UBound(Periods))
currenttime = DateDiff("n", Periods(i), FormatDateTime(Now(), 0))
If currenttime > 0 Then
If (currenttime <= PeriodInMinutes * i) Then
result = currenttime + (PeriodInMinutes * (i - 1))
Else
result = PeriodInMinutes * i
End If
End If
Next
GameTimer = result
End Function
Usage
Dim CurrentGameTime
Dim IceHockeyPeriods(3)
IceHockeyPeriods(1) = "2010-04-15 19:30"
IceHockeyPeriods(2) = "2010-04-15 20:00"
IceHockeyPeriods(3) = "2010-04-15 20:30"
CurrentGameTime = GameTimer(IceHockeyPeriods, 20)
Edit
Refactored to correct the flaw that between periods the full time is returned.