'
' Example script for 2BrightSparks SyncBackPro that stops a profile
' from being run more than once per day. If its a simulated run,
' or a restore, then it can be run regardless.
'
' SBLang=Basic
'
' http://www.2BrightSparks.com/
'

'
' This is a runtime script 
'
Function Description(ByRef ScriptType)
  Description = "Run at most once per day"
  ScriptType = SCRIPTTYPE_RUN
End Function

'
' We use the LastRunDT value from the profiles settings. It contains
' the last run date and time of the profile. If it has already been
' run today then we stop the profile running, and no log is created.
'
Function RunDisabledCheck(NoLog)
  ' Get the current date now just in case it changes while
  ' the string is being built
  RightNow = Date

  ' Create a string that has the current date in the
  ' format of YYYYMMDD
  NowDate = CStr(Year(RightNow))

  If Month(RightNow) < 10 Then
    NowDate = NowDate & "0" & CStr(Month(RightNow))
  Else
    NowDate = NowDate & CStr(Month(RightNow))
  End If

  If Day(RightNow) < 10 Then
    NowDate = NowDate & "0" & CStr(Day(RightNow))
  Else
    NowDate = NowDate & CStr(Day(RightNow))
  End If

  ' Get the date & time when this profile was
  ' last run. We are only interested in the date.
  LastRun = Left(SBVariables.GetProperty("LastRunDT", "00000000", TRUE), 8)

  ' Check to see if the profile has run
  If not SBRunning.Restore and not SBRunning.Simulated and LastRun = NowDate then
    RunDisabledCheck = "The profile has already been run on " & CStr(RightNow)
    NoLog = TRUE
  Else
    RunDisabledCheck = ""
    NoLog = FALSE
  End If
End Function
