home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / attall / atomic.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-05-07  |  11.7 KB  |  386 lines

  1. VERSION 2.00
  2. Begin Form Atomic 
  3.    BackColor       =   &H00C0C0C0&
  4.    BorderStyle     =   3  'Fixed Double
  5.    Caption         =   "Call the Atomic Clock"
  6.    ClientHeight    =   3915
  7.    ClientLeft      =   2460
  8.    ClientTop       =   930
  9.    ClientWidth     =   4725
  10.    Height          =   4320
  11.    Left            =   2400
  12.    LinkTopic       =   "Form1"
  13.    MaxButton       =   0   'False
  14.    MinButton       =   0   'False
  15.    ScaleHeight     =   3915
  16.    ScaleWidth      =   4725
  17.    Top             =   585
  18.    Width           =   4845
  19.    Begin MSComm Comm1 
  20.       Interval        =   1000
  21.       Left            =   3390
  22.       Top             =   1125
  23.    End
  24.    Begin SSCheck DST 
  25.       Caption         =   "Use Daylight Savings Time"
  26.       Font3D          =   0  'None
  27.       Height          =   285
  28.       Left            =   225
  29.       TabIndex        =   4
  30.       Top             =   960
  31.       Width           =   2640
  32.    End
  33.    Begin ComboBox TimeZone 
  34.       BackColor       =   &H00FFFFFF&
  35.       Height          =   300
  36.       Left            =   375
  37.       Style           =   2  'Dropdown List
  38.       TabIndex        =   3
  39.       Top             =   450
  40.       Width           =   4065
  41.    End
  42.    Begin CommandButton Command1 
  43.       Cancel          =   -1  'True
  44.       Caption         =   "Cancel"
  45.       Height          =   345
  46.       Index           =   2
  47.       Left            =   2370
  48.       TabIndex        =   1
  49.       Top             =   3300
  50.       Width           =   2085
  51.    End
  52.    Begin CommandButton Command1 
  53.       Caption         =   "Dial"
  54.       Default         =   -1  'True
  55.       Height          =   345
  56.       Index           =   1
  57.       Left            =   2370
  58.       TabIndex        =   0
  59.       Top             =   2790
  60.       Width           =   2070
  61.    End
  62.    Begin CommandButton Command1 
  63.       Caption         =   "Reset Defaults"
  64.       Height          =   345
  65.       Index           =   0
  66.       Left            =   2370
  67.       TabIndex        =   12
  68.       Top             =   2280
  69.       Width           =   2070
  70.    End
  71.    Begin SSFrame Frame3D1 
  72.       Caption         =   "COM Port"
  73.       Font3D          =   0  'None
  74.       ForeColor       =   &H00000000&
  75.       Height          =   1530
  76.       Left            =   255
  77.       TabIndex        =   7
  78.       Top             =   2190
  79.       Width           =   1965
  80.       Begin SSOption ComPort 
  81.          Caption         =   "COM&4:"
  82.          Font3D          =   0  'None
  83.          ForeColor       =   &H00000000&
  84.          Height          =   240
  85.          Index           =   3
  86.          Left            =   135
  87.          TabIndex        =   11
  88.          Top             =   1185
  89.          Width           =   780
  90.       End
  91.       Begin SSOption ComPort 
  92.          Caption         =   "COM&3:"
  93.          Font3D          =   0  'None
  94.          ForeColor       =   &H00000000&
  95.          Height          =   240
  96.          Index           =   2
  97.          Left            =   135
  98.          TabIndex        =   10
  99.          Top             =   885
  100.          Width           =   780
  101.       End
  102.       Begin SSOption ComPort 
  103.          Caption         =   "COM&2:"
  104.          Font3D          =   0  'None
  105.          ForeColor       =   &H00000000&
  106.          Height          =   240
  107.          Index           =   1
  108.          Left            =   135
  109.          TabIndex        =   9
  110.          Top             =   585
  111.          Width           =   780
  112.       End
  113.       Begin SSOption ComPort 
  114.          Caption         =   "COM&1:"
  115.          Font3D          =   0  'None
  116.          ForeColor       =   &H00000000&
  117.          Height          =   240
  118.          Index           =   0
  119.          Left            =   135
  120.          TabIndex        =   8
  121.          Top             =   285
  122.          Width           =   780
  123.       End
  124.    End
  125.    Begin TextBox DialString 
  126.       Height          =   300
  127.       Left            =   375
  128.       TabIndex        =   6
  129.       Text            =   "ATDT 1 303 494-4774"
  130.       Top             =   1710
  131.       Width           =   4080
  132.    End
  133.    Begin Label Status 
  134.       Alignment       =   1  'Right Justify
  135.       BackStyle       =   0  'Transparent
  136.       Height          =   240
  137.       Left            =   1125
  138.       TabIndex        =   13
  139.       Top             =   15
  140.       Width           =   3300
  141.    End
  142.    Begin Label Label1 
  143.       BackStyle       =   0  'Transparent
  144.       Caption         =   "Modem Dial String"
  145.       Height          =   210
  146.       Index           =   1
  147.       Left            =   225
  148.       TabIndex        =   5
  149.       Top             =   1440
  150.       Width           =   2145
  151.    End
  152.    Begin Label Label1 
  153.       BackStyle       =   0  'Transparent
  154.       Caption         =   "Time Zone"
  155.       Height          =   240
  156.       Index           =   0
  157.       Left            =   195
  158.       TabIndex        =   2
  159.       Top             =   165
  160.       Width           =   1320
  161.    End
  162. Option Explicit
  163. Declare Function GetProfileString Lib "Kernel" (ByVal lpAppName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Integer) As Integer
  164. Dim ControlsDisabled As Integer
  165. Dim InString As String
  166. Dim TString As String
  167. Dim Aborted As Integer
  168. Sub Command1_Click (Index As Integer)
  169. Dim StartTime As Double
  170. Dim I As Integer
  171. Dim NewD As Double
  172. Dim OldD As Double
  173. Dim DSTFlag As String
  174. Dim OffBy As String
  175. If Index = 0 Then  'Reset Defaults
  176.    ResetDefaults
  177.    Status.Caption = ""
  178. End If
  179. If Index = 1 Then  'Dial
  180.    SaveModemSettings
  181.    Aborted = False
  182.    Status.Caption = ""
  183.    Command1(0).Enabled = False
  184.    Command1(1).Enabled = False
  185.    TimeZone.Enabled = False
  186.    DST.Enabled = False
  187.    DialString.Enabled = False
  188.    Frame3D1.Enabled = False
  189.    ControlsDisabled = True
  190.    On Local Error GoTo ErrHndl
  191.    For I% = 0 To 3
  192.      If ComPort(I%).Value Then comm1.CommPort = I% + 1
  193.    Next I%
  194.    If Aborted Then Exit Sub
  195.    comm1.Settings = "1200,N,8,1"
  196.    If Aborted Then Exit Sub
  197.    comm1.PortOpen = True
  198.    If Aborted Then Exit Sub
  199.    comm1.Output = DialString.Text + Chr$(13) + Chr(10)
  200.    StartTime = Timer
  201.    LastTime = 0
  202.    Do
  203.       DoEvents
  204.       If LastTime <> Int(Timer) Then
  205.          If Not Aborted Then Status.Caption = "Connecting - " + Format$(45 - Int(Timer - StartTime)) + " seconds until timeout."
  206.          LastTime = Int(Timer)
  207.       End If
  208.    Loop Until comm1.InBufferCount >= 600 Or ((Timer - StartTime) > 45) Or Aborted
  209.    If Aborted Then Exit Sub
  210.    If (Timer - StartTime) > 45 Then
  211.          Status.Caption = "Timed out."
  212.          Exit Sub
  213.    End If
  214.    Status.Caption = "Setting time."
  215.    InString$ = comm1.Input
  216.    If Aborted Then Exit Sub
  217.    InString$ = Mid$(InString$, InStr(InString$, "*") + 1, 80)
  218.    NewD = DateValue(Mid$(InString$, 12, 2) + "/" + Mid$(InString$, 15, 2) + "/" + Mid$(InString$, 9, 2))
  219.    NewD = NewD + TimeValue(Mid$(InString$, 18, 8))
  220.    NewD = NewD - (TimeZone.ListIndex - 11) * (1 / 24)
  221.    DSTFlag$ = Mid$(InString$, 27, 2)
  222.    If ((DSTFlag >= "01") And (DSTFlag <= "50")) Then
  223.       NewD = NewD - (1 / 24)
  224.    End If
  225.    If DST.Value Then
  226.       NewD = NewD + (1 / 24)
  227.    End If
  228.    OldD = Date + Time
  229.    If Year(NewD) >= 1993 Then
  230.       Date = Format$(NewD, "mm/dd/yy")
  231.       Time = Format$(NewD, "hh:mm:ss")
  232.       If OldD > NewD Then
  233.          OffBy = "fast"
  234.       Else
  235.          OffBy = "slow"
  236.       End If
  237.       MsgBox "Time set to " + Format$(NewD, "hh:mm:ss") + ".  Clock was " + OffBy$ + " by " + Format$(Abs(NewD - OldD), "hh:mm:ss") + "."
  238.       AtomicTimeWasSet = True
  239.       Status.Caption = "Time set."
  240.    Else
  241.       MsgBox "Error getting date and time."
  242.    End If
  243.    If Aborted Then Exit Sub
  244.    HangUp
  245.    If Aborted Then Exit Sub
  246.    On Local Error Resume Next
  247.    Unload Atomic
  248. End If
  249. If Index = 2 Then  'Cancel
  250.    If ControlsDisabled Then
  251.       HangUp
  252.       EnableControls
  253.       Aborted = True
  254.       Status.Caption = "Aborted."
  255.    Else
  256.       Unload Atomic
  257.    End If
  258. End If
  259. EnableControls
  260. Exit Sub
  261. ErrHndl:
  262. MsgBox "Error: " + Error(Err)
  263. EnableControls
  264. Exit Sub
  265. End Sub
  266. Sub EnableControls ()
  267.    Command1(0).Enabled = True
  268.    Command1(1).Enabled = True
  269.    TimeZone.Enabled = True
  270.    DST.Enabled = True
  271.    DialString.Enabled = True
  272.    Frame3D1.Enabled = True
  273.    ControlsDisabled = False
  274. End Sub
  275. Sub Form_Load ()
  276. Atomic.Left = Settings.Left + (Settings.Width / 2) - (Atomic.Width / 2)
  277. Atomic.Top = Settings.Top + (Settings.Height / 2) - (Atomic.Height / 2)
  278. TimeZone.AddItem "Greenwich + 11"
  279. TimeZone.AddItem "Greenwich + 10"
  280. TimeZone.AddItem "Greenwich + 9"
  281. TimeZone.AddItem "Greenwich + 8"
  282. TimeZone.AddItem "Greenwich + 7"
  283. TimeZone.AddItem "Greenwich + 6"
  284. TimeZone.AddItem "Greenwich + 5"
  285. TimeZone.AddItem "Greenwich + 4"
  286. TimeZone.AddItem "Greenwich + 3"
  287. TimeZone.AddItem "Greenwich + 2"
  288. TimeZone.AddItem "Greenwich + 1"
  289. TimeZone.AddItem "Greenwich"
  290. TimeZone.AddItem "Greenwich - 1"
  291. TimeZone.AddItem "Greenwich - 2"
  292. TimeZone.AddItem "Greenwich - 3"
  293. TimeZone.AddItem "Atlantic Standard Time (4)"
  294. TimeZone.AddItem "Eastern Standard Time"
  295. TimeZone.AddItem "Central Time"
  296. TimeZone.AddItem "Mountain Time"
  297. TimeZone.AddItem "Pacific Time"
  298. TimeZone.AddItem "Yukon Standard Time"
  299. TimeZone.AddItem "Alaska-Hawaii Standard Time"
  300. TimeZone.AddItem "Nome Standard Time"
  301. TimeZone.AddItem "Greenwich - 12"
  302. ResetDefaults
  303. LoadModemSettings
  304. 'Atomic.Show 1
  305. 'Command1(1).SetFocus
  306. End Sub
  307. Sub HangUp ()
  308.    Dim StartTime As Double
  309.    Dim I As Integer
  310.    Dim Ret As Integer
  311.    'Beep
  312.    On Local Error GoTo ErrHndl2
  313.    'comm1.Output = "+++"
  314.    'StartTime = Timer
  315.    'While Timer - StartTime < .5
  316.    '  DoEvents
  317.    'Wend
  318.    'comm1.Output = "ATH0" + Chr$(13) + Chr(10)
  319.    For I% = 1 To 3
  320.    StartTime = Timer
  321.    TString$ = comm1.Input
  322.    comm1.Output = "+"
  323.    While Timer - StartTime < .5
  324.      DoEvents
  325.    Wend
  326.    Next I%
  327.    'Do
  328.    '   DoEvents
  329.    'Loop Until comm1.InBufferCount >= 2
  330.    comm1.Output = "ATH0" + Chr(13) + Chr(10)
  331.    StartTime = Timer
  332.    Do
  333.       DoEvents
  334.    Loop Until comm1.InBufferCount >= 2 Or (Timer - StartTime) > 5
  335.    TString$ = comm1.Input
  336.    comm1.Output = "+++"
  337.    StartTime = Timer
  338.    While Timer - StartTime < .5
  339.      DoEvents
  340.    Wend
  341.    comm1.Output = "ATH0" + Chr$(13) + Chr(10)
  342.    Ret = comm1.DTREnable     'Save current setting
  343.    comm1.DTREnable = True    'Turn DTR on
  344.      DoEvents
  345.    comm1.DTREnable = False   'Turn DTR off
  346.      DoEvents
  347.    comm1.DTREnable = Ret     'Restore old setting
  348.    comm1.PortOpen = False
  349. ErrHndl2:
  350.   EnableControls
  351.   Exit Sub
  352. End Sub
  353. Sub LoadModemSettings ()
  354. Dim lpReturnedString As String * 100
  355. Dim A As Integer
  356. lpReturnedString = Space$(100)
  357. A% = GetProfileString("AllTheTime", "TimeZoneIndex", "16", lpReturnedString$, 100)
  358. TimeZone.ListIndex = Val(lpReturnedString)
  359. A% = GetProfileString("AllTheTime", "DST", "0", lpReturnedString$, 100)
  360. DST.Value = Val(lpReturnedString)
  361. A% = GetProfileString("AllTheTime", "DialString", "ATDT 1 303 494-4774", lpReturnedString$, 100)
  362. DialString.Text = lpReturnedString
  363. A% = GetProfileString("AllTheTime", "ComPort", "0", lpReturnedString$, 100)
  364. ComPort(Val(lpReturnedString)).Value = True
  365. End Sub
  366. Sub ResetDefaults ()
  367.    TimeZone.ListIndex = 16
  368.    DST.Value = 0
  369.    DialString.Text = "ATDT 1 303 494-4774"
  370.    ComPort(0).Value = True
  371.    'LoadModemSettings
  372. End Sub
  373. Sub SaveModemSettings ()
  374. Dim A As Integer
  375. Dim M As String
  376. Dim I As Integer
  377. A% = WriteProfileString("AllTheTime", "TimeZoneIndex", TimeZone.ListIndex)
  378. A% = WriteProfileString("AllTheTime", "DST", DST.Value)
  379. A% = WriteProfileString("AllTheTime", "DialString", DialString.Text)
  380. M$ = "0"
  381. For I% = 0 To 3
  382.    If ComPort(I%).Value Then M$ = Str$(I%)
  383. Next I%
  384. A% = WriteProfileString("AllTheTime", "ComPort", M$)
  385. End Sub
  386.