I call the following function with
Call GameTimer(FormatDate(objLiveCommentary("DateFirstStarted"), "WithTime"),
FormatDate(objLiveCommentary("DateSecondStarted"), "WithTime"),
"Soccer")
And it prints results as 23, 35, 64, 90. I want to take this result and store it as
CurrentGameTime =
because I will save CurrentGameTime to my database. How can I do it?
Function GameTimer (FirstStarted, SecondStarted, GameType)
If GameType = "Soccer" Then
DateFirstStarted = DateDiff("n", FirstStarted, FormatDate(NOW(), "WithTime"))
DateSecondStarted = DateDiff("n", SecondStarted, FormatDate(NOW(), "WithTime"))
If DateFirstStarted <= 45 Then
Response.Write DateFirstStarted
ElseIf DateFirstStarted <= 45 Then
DateFirstStarted
ElseIf DateSecondStarted <= 45 Then
Response.Write DateSecondStarted + 45
ElseIf DateFirstStarted <= 45 Then
DateFirstStarted
Else
Response.Write "90"
End If
End If
End Function
To return the result of your Function you need to set the Functions return value:
Your GameTimer Function should look something like this:
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:
Usage
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
Usage
Edit
Refactored to correct the flaw that between periods the full time is returned.