Sample: Script

Reads the time from the US Naval Observatory web site into an Offline document and compares it with the computer. Uses the text connector.

http://inters.com/samples/time.olz

The package contains Time OL and OLB files. Select Enabled in the Formula tab to run after opening.

To enable on startup, click Startup in the Formula tab. If the Output window is not displayed, click Output in the App tab.

Note the message in the Debug tab of the Output window (for example: Computer time matches Usno time).

Press Run in the Formula tab to run the sccipt again.

Click Edit Formula. Click Full Module View to display the Script.

Sub Main
    Full Dim sUsno, sWarning, sUrl
    Dim dUsno, dNow
    Dim nSecondsOff, nTolerance
    'Update Grid
    sUrl=Grid.LinkProperties(2)
    If Not Grid.DataRead( &h100 ) Then '&h100 means Reload Update
        App.History.Debug.Prompt "Could not Update from " & sUrl & "."
    End If
    If Grid.Cell("Text",4)<>"<TITLE>What time is it?</TITLE>" Then
        App.History.Debug.Prompt "Unexpected: " & Grid.Cell("Text",4)
    End If
    dNow=now

    'Format string to convert with DateValue and TimeValue
    sUsno=Grid.Cell("Text",7) '<BR>Feb. 09, 10:47:01 AM EST Eastern Time
    sUsno=Mid(sUsno, 5, 17) 'Feb. 09, 10:47:01 AM
    sUsno=Replace(sUsno, ",", "") 'Feb. 09 10:47:01 AM
    dUsno=DateValue(sUsno)+TimeValue(sUsno)
     'Debug
    App.History.Debug.Prompt("dNow: "& formatdatetime(dNow, vbLongdate)& " " & formatdatetime(dNow, vbLongtime))
    App.History.Debug.Prompt("dUsno: "& formatdatetime(dUsno, vbLongdate)& " " & formatdatetime(dUsno, vbLongtime))

    'Compare the time in minutes and seconds
    nSecondsOff=DateDiff("s", dUsno, dNow)
    nSecondsOff=nSecondsOff Mod (60*60) 'Support all time zones (exclude hours)

    'Check
    '================
    nTolerance=3 '3 Seconds for lag
    '================

    sMsg = "Computer time matches Usno time."
    If (nSecondsOff<-nTolerance) Then
    sMsg="Computer is " & nSecondsOff & " seconds ahead of Usno time."
    End If
    If (nSecondsOff<-nTolerance) Then
    s    Msg="Computer is " & -nSecondsOff & " seconds behind Usno time."
    End If

    App.History.Debug.Prompt (sMsg)
    App.History.Debug.Activate
    app.StatusBar=sMsg

End Sub

If you wanted to run from Macro menu click Macros in the Formula tab to display the Macros dialog box.

Click Add Global to add Main to the list. A global loads time.ol and time.olb if they are not already loaded.

To test the macro close all documents (without saving) and click Main under Macros in the Formula tab.


SQL Offline © 2014 Interscape Corporation