VERSION 5.00
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX"
Begin VB.Form Form1 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "برنامه کنترل تلفن"
   ClientHeight    =   7395
   ClientLeft      =   150
   ClientTop       =   540
   ClientWidth     =   11520
   Icon            =   "Form1.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   7395
   ScaleWidth      =   11520
   StartUpPosition =   3  'Windows Default
   Visible         =   0   'False
   WhatsThisHelp   =   -1  'True
   Begin VB.CommandButton Command9 
      Caption         =   "Clear List1"
      Height          =   300
      Left            =   240
      TabIndex        =   52
      Top             =   5535
      Width           =   1200
   End
   Begin VB.CommandButton Command8 
      Caption         =   "Set"
      Height          =   285
      Left            =   225
      TabIndex        =   51
      Top             =   6555
      Width           =   1740
   End
   Begin VB.TextBox Tlen 
      Height          =   315
      Left            =   225
      TabIndex        =   50
      Text            =   "7"
      Top             =   6135
      Width           =   1770
   End
   Begin VB.ListBox List1 
      Height          =   2400
      Left            =   3015
      TabIndex        =   40
      Top             =   4785
      Width           =   8340
   End
   Begin VB.CommandButton Command1 
      Caption         =   "Clear Line Out"
      Height          =   300
      Left            =   240
      TabIndex        =   39
      Top             =   5190
      Width           =   1200
   End
   Begin VB.TextBox TxtDecode 
      Alignment       =   1  'Right Justify
      Height          =   390
      Left            =   3525
      ScrollBars      =   2  'Vertical
      TabIndex        =   22
      Top             =   195
      Width           =   7875
   End
   Begin VB.CommandButton Command5 
      Caption         =   "Clear Line In"
      Height          =   300
      Left            =   240
      TabIndex        =   21
      Top             =   4830
      Width           =   1230
   End
   Begin VB.Frame Frame4 
      Caption         =   "Line4"
      Height          =   3765
      Left            =   8700
      TabIndex        =   16
      Top             =   915
      Width           =   2700
      Begin VB.TextBox Text4 
         Height          =   285
         Left            =   1125
         TabIndex        =   48
         Text            =   "500"
         Top             =   3285
         Width           =   615
      End
      Begin VB.CommandButton Command7 
         Caption         =   "Set"
         Height          =   285
         Left            =   1800
         TabIndex        =   47
         Top             =   3285
         Width           =   615
      End
      Begin VB.Timer TL4CallerID 
         Enabled         =   0   'False
         Interval        =   500
         Left            =   660
         Top             =   3345
      End
      Begin VB.TextBox L4Ring 
         BackColor       =   &H0080FFFF&
         Height          =   315
         Left            =   195
         TabIndex        =   38
         Top             =   1665
         Width           =   2310
      End
      Begin VB.OptionButton L4HangUp 
         Alignment       =   1  'Right Justify
         Caption         =   "گوشي برداشته"
         BeginProperty Font 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   178
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   345
         Left            =   1050
         RightToLeft     =   -1  'True
         TabIndex        =   37
         Top             =   2850
         Width           =   1380
      End
      Begin VB.OptionButton L4HangDown 
         Alignment       =   1  'Right Justify
         Caption         =   "گوشي گذاشته"
         BeginProperty Font 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   178
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   345
         Left            =   1050
         RightToLeft     =   -1  'True
         TabIndex        =   36
         Top             =   2535
         Value           =   -1  'True
         Width           =   1380
      End
      Begin VB.Timer TDetectHangUp4 
         Enabled         =   0   'False
         Interval        =   200
         Left            =   135
         Top             =   2460
      End
      Begin VB.Timer TDetectHangDown4 
         Enabled         =   0   'False
         Interval        =   150
         Left            =   150
         Top             =   2940
      End
      Begin VB.TextBox L4Tone 
         BackColor       =   &H0080FFFF&
         Height          =   315
         Left            =   195
         TabIndex        =   35
         Top             =   2055
         Width           =   2310
      End
      Begin VB.Timer TToneL4 
         Enabled         =   0   'False
         Interval        =   500
         Left            =   165
         Top             =   3435
      End
      Begin VB.TextBox T4L4 
         Height          =   315
         Left            =   165
         TabIndex        =   20
         Text            =   "0"
         Top             =   1290
         Width           =   2310
      End
      Begin VB.TextBox T3L4 
         Height          =   315
         Left            =   195
         TabIndex        =   19
         Text            =   "0"
         Top             =   960
         Width           =   2310
      End
      Begin VB.TextBox T2L4 
         Height          =   315
         Left            =   195
         TabIndex        =   18
         Text            =   "0"
         Top             =   630
         Width           =   2310
      End
      Begin VB.TextBox T1L4 
         Height          =   315
         Left            =   195
         TabIndex        =   17
         Text            =   "0"
         Top             =   300
         Width           =   2310
      End
   End
   Begin VB.Frame Frame3 
      Caption         =   "Line3"
      Height          =   3765
      Left            =   5865
      TabIndex        =   11
      Top             =   915
      Width           =   2700
      Begin VB.TextBox Text3 
         Height          =   285
         Left            =   1185
         TabIndex        =   46
         Text            =   "500"
         Top             =   3330
         Width           =   615
      End
      Begin VB.CommandButton Command6 
         Caption         =   "Set"
         Height          =   285
         Left            =   1860
         TabIndex        =   45
         Top             =   3330
         Width           =   615
      End
      Begin VB.Timer TL3CallerID 
         Enabled         =   0   'False
         Interval        =   500
         Left            =   690
         Top             =   3345
      End
      Begin VB.TextBox L3Ring 
         BackColor       =   &H0080FFFF&
         Height          =   315
         Left            =   195
         TabIndex        =   34
         Top             =   1665
         Width           =   2310
      End
      Begin VB.OptionButton L3HangUp 
         Alignment       =   1  'Right Justify
         Caption         =   "گوشي برداشته"
         BeginProperty Font 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   178
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   345
         Left            =   1125
         RightToLeft     =   -1  'True
         TabIndex        =   33
         Top             =   2850
         Width           =   1380
      End
      Begin VB.OptionButton L3HangDown 
         Alignment       =   1  'Right Justify
         Caption         =   "گوشي گذاشته"
         BeginProperty Font 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   178
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   345
         Left            =   1125
         RightToLeft     =   -1  'True
         TabIndex        =   32
         Top             =   2535
         Value           =   -1  'True
         Width           =   1380
      End
      Begin VB.Timer TDetectHangUp3 
         Enabled         =   0   'False
         Interval        =   200
         Left            =   195
         Top             =   2460
      End
      Begin VB.Timer TDetectHangDown3 
         Enabled         =   0   'False
         Interval        =   150
         Left            =   180
         Top             =   2895
      End
      Begin VB.TextBox L3Tone 
         BackColor       =   &H0080FFFF&
         Height          =   315
         Left            =   195
         TabIndex        =   31
         Top             =   2040
         Width           =   2310
      End
      Begin VB.Timer TToneL3 
         Enabled         =   0   'False
         Interval        =   500
         Left            =   210
         Top             =   3360
      End
      Begin VB.TextBox T4L3 
         Height          =   315
         Left            =   195
         TabIndex        =   15
         Text            =   "0"
         Top             =   1290
         Width           =   2310
      End
      Begin VB.TextBox T3L3 
         Height          =   315
         Left            =   195
         TabIndex        =   14
         Text            =   "0"
         Top             =   960
         Width           =   2310
      End
      Begin VB.TextBox T2L3 
         Height          =   315
         Left            =   195
         TabIndex        =   13
         Text            =   "0"
         Top             =   630
         Width           =   2310
      End
      Begin VB.TextBox T1L3 
         Height          =   315
         Left            =   195
         TabIndex        =   12
         Text            =   "0"
         Top             =   300
         Width           =   2310
      End
   End
   Begin VB.Frame Frame2 
      Caption         =   "Line2"
      Height          =   3765
      Left            =   3030
      TabIndex        =   6
      Top             =   915
      Width           =   2700
      Begin VB.TextBox Text2 
         Height          =   285
         Left            =   1140
         TabIndex        =   44
         Text            =   "500"
         Top             =   3300
         Width           =   615
      End
      Begin VB.CommandButton Command4 
         Caption         =   "Set"
         Height          =   285
         Left            =   1815
         TabIndex        =   43
         Top             =   3300
         Width           =   615
      End
      Begin VB.Timer TL2CallerID 
         Enabled         =   0   'False
         Interval        =   500
         Left            =   825
         Top             =   3300
      End
      Begin VB.TextBox L2Ring 
         BackColor       =   &H0080FFFF&
         Height          =   315
         Left            =   195
         TabIndex        =   30
         Top             =   1665
         Width           =   2310
      End
      Begin VB.OptionButton L2HangUp 
         Alignment       =   1  'Right Justify
         Caption         =   "گوشي برداشته"
         BeginProperty Font 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   178
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   345
         Left            =   1050
         RightToLeft     =   -1  'True
         TabIndex        =   29
         Top             =   2865
         Width           =   1380
      End
      Begin VB.OptionButton L2HangDown 
         Alignment       =   1  'Right Justify
         Caption         =   "گوشي گذاشته"
         BeginProperty Font 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   178
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   345
         Left            =   1050
         RightToLeft     =   -1  'True
         TabIndex        =   28
         Top             =   2550
         Value           =   -1  'True
         Width           =   1380
      End
      Begin VB.Timer TDetectHangUp2 
         Enabled         =   0   'False
         Interval        =   200
         Left            =   300
         Top             =   2505
      End
      Begin VB.Timer TDetectHangDown2 
         Enabled         =   0   'False
         Interval        =   150
         Left            =   300
         Top             =   2955
      End
      Begin VB.TextBox L2Tone 
         BackColor       =   &H0080FFFF&
         Height          =   315
         Left            =   195
         TabIndex        =   27
         Top             =   2040
         Width           =   2310
      End
      Begin VB.Timer TToneL2 
         Enabled         =   0   'False
         Interval        =   500
         Left            =   285
         Top             =   3420
      End
      Begin VB.TextBox T4L2 
         Height          =   315
         Left            =   195
         TabIndex        =   10
         Text            =   "0"
         Top             =   1290
         Width           =   2310
      End
      Begin VB.TextBox T3L2 
         Height          =   315
         Left            =   195
         TabIndex        =   9
         Text            =   "0"
         Top             =   960
         Width           =   2310
      End
      Begin VB.TextBox T2L2 
         Height          =   315
         Left            =   195
         TabIndex        =   8
         Text            =   "0"
         Top             =   630
         Width           =   2310
      End
      Begin VB.TextBox T1L2 
         Height          =   315
         Left            =   195
         TabIndex        =   7
         Text            =   "0"
         Top             =   300
         Width           =   2310
      End
   End
   Begin VB.Frame Frame1 
      Caption         =   "Line1"
      Height          =   3765
      Left            =   240
      TabIndex        =   1
      Top             =   915
      Width           =   2700
      Begin VB.CommandButton Command3 
         Caption         =   "Set"
         Height          =   285
         Left            =   1620
         TabIndex        =   42
         Top             =   3345
         Width           =   615
      End
      Begin VB.TextBox Text1 
         Height          =   285
         Left            =   945
         TabIndex        =   41
         Text            =   "500"
         Top             =   3345
         Width           =   615
      End
      Begin VB.Timer TL1CallerID 
         Enabled         =   0   'False
         Interval        =   500
         Left            =   720
         Top             =   3330
      End
      Begin VB.TextBox L1Ring 
         BackColor       =   &H0080FFFF&
         Height          =   315
         Left            =   210
         TabIndex        =   26
         Top             =   1680
         Width           =   2310
      End
      Begin VB.Timer TDetectHangUp1 
         Enabled         =   0   'False
         Interval        =   800
         Left            =   225
         Top             =   2490
      End
      Begin VB.OptionButton L1HangDown 
         Alignment       =   1  'Right Justify
         Caption         =   "گوشي گذاشته"
         BeginProperty Font 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   178
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   345
         Left            =   900
         RightToLeft     =   -1  'True
         TabIndex        =   25
         Top             =   2655
         Value           =   -1  'True
         Width           =   1380
      End
      Begin VB.OptionButton L1HangUp 
         Alignment       =   1  'Right Justify
         Caption         =   "گوشي برداشته"
         BeginProperty Font 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   178
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   345
         Left            =   900
         RightToLeft     =   -1  'True
         TabIndex        =   24
         Top             =   2970
         Width           =   1380
      End
      Begin VB.Timer TDetectHangDown1 
         Enabled         =   0   'False
         Interval        =   150
         Left            =   240
         Top             =   2910
      End
      Begin VB.Timer TToneL1 
         Enabled         =   0   'False
         Interval        =   500
         Left            =   240
         Top             =   3300
      End
      Begin VB.TextBox L1Tone 
         BackColor       =   &H0080FFFF&
         Height          =   315
         Left            =   210
         TabIndex        =   23
         Top             =   2070
         Width           =   2310
      End
      Begin VB.TextBox T1L1 
         Height          =   315
         Left            =   195
         TabIndex        =   5
         Text            =   "0"
         Top             =   300
         Width           =   2310
      End
      Begin VB.TextBox T2L1 
         Height          =   315
         Left            =   195
         TabIndex        =   4
         Text            =   "0"
         Top             =   615
         Width           =   2310
      End
      Begin VB.TextBox T3L1 
         Height          =   315
         Left            =   195
         TabIndex        =   3
         Text            =   "0"
         Top             =   960
         Width           =   2310
      End
      Begin VB.TextBox T4L1 
         Height          =   315
         Left            =   195
         TabIndex        =   2
         Text            =   "0"
         Top             =   1290
         Width           =   2310
      End
   End
   Begin VB.Timer TDecode 
      Interval        =   5
      Left            =   3120
      Top             =   180
   End
   Begin VB.Timer Timer1 
      Interval        =   10
      Left            =   2640
      Top             =   210
   End
   Begin VB.CommandButton Command2 
      Caption         =   "DisConnect CallerID Hardware"
      Height          =   405
      Left            =   270
      TabIndex        =   0
      Top             =   165
      Width           =   2325
   End
   Begin MSCommLib.MSComm MSComm1 
      Left            =   4815
      Top             =   300
      _ExtentX        =   1005
      _ExtentY        =   1005
      _Version        =   393216
      DTREnable       =   -1  'True
      RThreshold      =   1
      BaudRate        =   4800
      SThreshold      =   1
   End
   Begin VB.Label Label1 
      Caption         =   "Number Length:"
      Height          =   360
      Left            =   240
      TabIndex        =   49
      Top             =   5925
      Width           =   1245
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit



Dim DataHangDown1 As String
Dim DataHangDown2 As String
Dim DataHangDown3 As String
Dim DataHangDown4 As String

Dim CounterHangDown1 As Integer
Dim CounterHangDown2 As Integer
Dim CounterHangDown3 As Integer
Dim CounterHangDown4 As Integer

Dim CounterHangUp1 As Integer
Dim CounterHangUp2 As Integer
Dim CounterHangUp3 As Integer
Dim CounterHangUp4 As Integer

Dim FlagAddDataFromCom As Boolean
Dim TimeAddData As Boolean
Dim MyData As String
Dim Level1 As String
Dim Level2 As String
Dim RecData As String
Private Sub Command1_Click()
L3Tone.Text = ""
L4Tone.Text = ""
L1Tone.Text = ""
L2Tone.Text = ""
End Sub

Private Sub Command2_Click()
MSComm1.PortOpen = False
End Sub
Private Sub Command3_Click()
TL1CallerID.Interval = Text1.Text
Cnn.Execute ("update setting set line1timer=" & Text1.Text)
End Sub

Private Sub Command4_Click()
TL2CallerID.Interval = Text2.Text
Cnn.Execute ("update setting set line2timer=" & Text2.Text)
End Sub

Private Sub Command5_Click()
L1Ring.Text = ""
L2Ring.Text = ""
L3Ring.Text = ""
L4Ring.Text = ""
End Sub

Private Sub Command6_Click()
TL3CallerID.Interval = Text3.Text
Cnn.Execute ("update setting set line3timer=" & Text3.Text)
End Sub

Private Sub Command7_Click()
TL4CallerID.Interval = Text4.Text
Cnn.Execute ("update setting set line4timer=" & Text4.Text)
End Sub
Private Sub Command8_Click()
Cnn.Execute ("update setting set NumberLength=" & Tlen.Text)
End Sub

Private Sub Command9_Click()
List1.Clear
End Sub

Private Sub Form_Load()
Call OpenConnection(Cnn, "Taxi-Service_3.0", 2)
FlagAddDataFromCom = False
Load Form2
Form2.Show
Dim CallerIdPort As String
Dim Line1Timer As String
Dim Line2Timer As String
Dim Line3Timer As String
Dim Line4Timer As String
Dim NumberLength As String
NumberLength = Space("255")
Line4Timer = Space("255")
Line3Timer = Space("255")
Line2Timer = Space("255")
Line1Timer = Space("255")
CallerIdPort = Space("255")
GetPrivateProfileString "Setting", "CallerIDPort", 1, CallerIdPort, 255, App.Path & "\Setting.ini"
GetPrivateProfileString "Setting", "Line1Timer", 1, Line1Timer, 255, App.Path & "\Setting.ini"
GetPrivateProfileString "Setting", "Line2Timer", 1, Line2Timer, 255, App.Path & "\Setting.ini"
GetPrivateProfileString "Setting", "Line3Timer", 1, Line3Timer, 255, App.Path & "\Setting.ini"
GetPrivateProfileString "Setting", "Line4Timer", 1, Line4Timer, 255, App.Path & "\Setting.ini"
GetPrivateProfileString "Setting", "NumberLength", 1, NumberLength, 255, App.Path & "\Setting.ini"

Text1.Text = Line1Timer
Text2.Text = Line2Timer
Text3.Text = Line3Timer
Text4.Text = Line4Timer
Tlen.Text = NumberLength
TL1CallerID.Interval = Text1.Text
TL2CallerID.Interval = Text2.Text
TL3CallerID.Interval = Text3.Text
TL4CallerID.Interval = Text4.Text
Form2.Tport.Text = CallerIdPort

End Sub
Private Sub AddRingNumber(line As Byte, Number As String)
Cnn.Execute ("insert into numberlist (line,number) values (" & line & ",'" & Number & "')")
Form2.TelList.AddItem "خط  " & line & " : " & Number
End Sub
Private Sub Form_Unload(Cancel As Integer)
If MSComm1.PortOpen = True Then MSComm1.PortOpen = False
End
End Sub

Private Sub List1_DblClick()
TxtDecode.Text = List1.Text
End Sub
Private Sub MSComm1_OnComm()
'On Error Resume Next
If MSComm1.CommEvent = comEvReceive Then
    RecData = Trim(MSComm1.Input)
    FlagAddDataFromCom = True
    MyData = MyData & RecData
    FlagAddDataFromCom = False
End If
End Sub
Private Sub T1L1_Change()
If TL1CallerID.Enabled = True Then
    TL1CallerID.Enabled = False
    TL1CallerID.Enabled = True
Else
    TL1CallerID.Enabled = True
End If
If L1HangUp.Value = True Then
    If TToneL1.Enabled = True Then
        TToneL1.Enabled = False
        TToneL1.Enabled = True
    Else
        TToneL1.Enabled = True
    End If
End If
End Sub

Private Sub T1L2_Change()
If TL2CallerID.Enabled = True Then
    TL2CallerID.Enabled = False
    TL2CallerID.Enabled = True
Else
    TL2CallerID.Enabled = True
End If
If L2HangUp.Value = True Then
    If TToneL2.Enabled = True Then
        TToneL2.Enabled = False
        TToneL2.Enabled = True
    Else
        TToneL2.Enabled = True
    End If
End If
End Sub

Private Sub T1L3_Change()
If TL3CallerID.Enabled = True Then
    TL3CallerID.Enabled = False
    TL3CallerID.Enabled = True
Else
    TL3CallerID.Enabled = True
End If
If L3HangUp.Value = True Then
    If TToneL3.Enabled = True Then
        TToneL3.Enabled = False
        TToneL3.Enabled = True
    Else
        TToneL3.Enabled = True
    End If
End If
End Sub

Private Sub T1L4_Change()
If TL4CallerID.Enabled = True Then
    TL4CallerID.Enabled = False
    TL4CallerID.Enabled = True
Else
    TL4CallerID.Enabled = True
End If
If L4HangUp.Value = True Then
    If TToneL4.Enabled = True Then
        TToneL4.Enabled = False
        TToneL4.Enabled = True
    Else
        TToneL4.Enabled = True
    End If
End If
End Sub

Private Sub TDecode_Timer()
If TimeAddData = True Then Exit Sub
If Len(Level2) = 0 Then
    If Len(TxtDecode.Text) > 0 Then
        Call Send(TxtDecode.Text)
        TxtDecode.Text = ""
    End If
    Exit Sub
End If
If Asc(Left(Level2, 2)) = 10 Or Asc(Left(Level2, 2)) = 13 Then
    Level2 = Right(Level2, Len(Level2) - 1)
    If Len(TxtDecode.Text) > 0 Then Call Send(TxtDecode.Text)
    TxtDecode.Text = ""
Else
    TxtDecode.Text = TxtDecode.Text & Trim(Left(Level2, 1))
    Level2 = Right(Level2, Len(Level2) - 1)
End If
End Sub
Private Sub Send(str As String)

'On Error Resume Next
Select Case Left(str, 1)
Case 1
    T4L1.Text = T3L1.Text
    T3L1.Text = T2L1.Text
    T2L1.Text = T1L1.Text
    T1L1.Text = Trim(Right(str, Len(str) - 2))
    Call DecodeHistory(1)
Case 2
    T4L2.Text = T3L2.Text
    T3L2.Text = T2L2.Text
    T2L2.Text = T1L2.Text
    T1L2.Text = Trim(Right(str, Len(str) - 2))
    Call DecodeHistory(2)
Case 3
    T4L3.Text = T3L3.Text
    T3L3.Text = T2L3.Text
    T2L3.Text = T1L3.Text
    T1L3.Text = Trim(Right(str, Len(str) - 2))
    Call DecodeHistory(3)
Case 4
    T4L4.Text = T3L4.Text
    T3L4.Text = T2L4.Text
    T2L4.Text = T1L4.Text
    T1L4.Text = Trim(Right(str, Len(str) - 2))
    Call DecodeHistory(4)
End Select
End Sub
Private Sub DecodeHistory(line As Byte)
Call DetectHangUp(line)
Call DetectHangDown(line)
End Sub

Private Sub DetectHangUp(line As Byte)
Select Case line
Case 1
    If Len(T1L1.Text) <> 0 Then Exit Sub
    CounterHangUp1 = 0
    Print "enableTimer"
    TDetectHangUp1.Enabled = True
Case 2
    If Len(T1L2.Text) <> 0 Then Exit Sub
    CounterHangUp2 = 0
    TDetectHangUp2.Enabled = True
Case 3
    If Len(T1L3.Text) <> 0 Then Exit Sub
    CounterHangUp3 = 0
    TDetectHangUp3.Enabled = True
Case 4
    If Len(T1L4.Text) <> 0 Then Exit Sub
    CounterHangUp4 = 0
    TDetectHangUp4.Enabled = True
End Select
End Sub
Private Sub DetectHangDown(line As Byte)
Select Case line
Case 1
    If L1HangUp.Value = False Then Exit Sub
    If InStr(T1L1.Text, "-") = 0 Then Exit Sub
    CounterHangDown1 = 0
    DataHangDown1 = T1L1.Text
    TDetectHangDown1.Enabled = True
Case 2
    If L2HangUp.Value = False Then Exit Sub
    If InStr(T1L2.Text, "-") = 0 Then Exit Sub
    CounterHangDown2 = 0
    TDetectHangDown2.Enabled = True
Case 3
    If L3HangUp.Value = False Then Exit Sub
    If InStr(T1L3.Text, "-") = 0 Then Exit Sub
    CounterHangDown1 = 0
    TDetectHangDown3.Enabled = True
Case 4
    If L4HangUp.Value = False Then Exit Sub
    If InStr(T1L4.Text, "-") = 0 Then Exit Sub
    CounterHangDown1 = 0
    TDetectHangDown4.Enabled = True
End Select
End Sub
Private Sub TDetectHangDown1_Timer()
If InStr(T1L1.Text, "-") <> 0 Then
    If DataHangDown1 = T1L1.Text Then
        CounterHangDown1 = CounterHangDown1 + 1
    Else
        DataHangDown1 = T1L1.Text
        CounterHangDown1 = 0
    End If
End If

If CounterHangDown1 = 10 Then
    L1HangDown.Value = True
    L1Tone.Text = ""
    TDetectHangDown1.Enabled = False
    TToneL1.Enabled = False
End If
End Sub
Private Sub TDetectHangDown2_Timer()
If InStr(T1L2.Text, "-") <> 0 Then
    If DataHangDown2 = T1L2.Text Then
        CounterHangDown2 = CounterHangDown2 + 1
    Else
        DataHangDown2 = T1L2.Text
        CounterHangDown2 = 0
    End If
End If

If CounterHangDown2 = 10 Then
    L2HangDown.Value = True
    L2Tone.Text = ""
    TDetectHangDown2.Enabled = False
    TToneL2.Enabled = False
End If
End Sub

Private Sub TDetectHangDown3_Timer()
If InStr(T1L3.Text, "-") <> 0 Then
    If DataHangDown3 = T1L3.Text Then
        CounterHangDown3 = CounterHangDown3 + 1
    Else
        DataHangDown3 = T1L3.Text
        CounterHangDown3 = 0
    End If
End If

If CounterHangDown3 = 10 Then
    L3HangDown.Value = True
    L3Tone.Text = ""
    TDetectHangDown3.Enabled = False
    TToneL3.Enabled = False
End If
End Sub

Private Sub TDetectHangDown4_Timer()
If InStr(T1L4.Text, "-") <> 0 Then
    If DataHangDown4 = T1L4.Text Then
        CounterHangDown4 = CounterHangDown4 + 1
    Else
        DataHangDown4 = T1L4.Text
        CounterHangDown4 = 0
    End If
End If

If CounterHangDown4 = 10 Then
    L4HangDown.Value = True
    L4Tone.Text = ""
    TDetectHangDown4.Enabled = False
    TToneL4.Enabled = False
End If
End Sub

Private Sub TDetectHangUp2_Timer()
If Len(T1L2.Text) = 0 Then CounterHangUp2 = CounterHangUp2 + 1
If CounterHangUp2 = 3 Then
    L2HangUp.Value = True
        TToneL2.Enabled = True
    TDetectHangUp2 = False
ElseIf CounterHangUp2 = 5 Then
    TDetectHangUp2 = False
End If
End Sub

Private Sub TDetectHangUp3_Timer()
If Len(T1L3.Text) = 0 Then CounterHangUp3 = CounterHangUp3 + 1
If CounterHangUp3 = 3 Then
    L3HangUp.Value = True
        TToneL3.Enabled = True
    TDetectHangUp3 = False
ElseIf CounterHangUp3 = 5 Then
    TDetectHangUp3 = False
End If
End Sub

Private Sub TDetectHangUp4_Timer()
If Len(T1L4.Text) = 0 Then CounterHangUp4 = CounterHangUp4 + 1
If CounterHangUp4 = 3 Then
    L4HangUp.Value = True
        TToneL4.Enabled = True
    TDetectHangUp4 = False
ElseIf CounterHangUp4 = 5 Then
    TDetectHangUp4 = False
End If
End Sub


Private Sub TL1CallerID_Timer()
If Left(T1L1, 4) = "8888" Then
    Exit Sub
    TL1CallerID.Enabled = False
End If

If (Len(T1L1.Text) >= Tlen.Text) And Len(T2L1.Text) = 0 Then
       If IsNumeric(T1L1.Text) = True Then Call AddRingNumber(1, T1L1.Text)
ElseIf (Len(T1L1.Text) >= Tlen.Text) And (Len(T3L1.Text) = 0) Then
       If IsNumeric(T1L1.Text) = True Then Call AddRingNumber(1, T1L1.Text)
   End If
TL1CallerID.Enabled = False
End Sub


Private Sub TL2CallerID_Timer()
If Left(T1L2, 4) = "8888" Then
    Exit Sub
    TL2CallerID.Enabled = False
End If

If (Len(T1L2.Text) >= Tlen.Text) Then 'And Len(T2L2.Text) = 0 Then
       If IsNumeric(T1L2.Text) = True Then Call AddRingNumber(2, T1L2.Text)
End If
'ElseIf (Len(T1L2.Text) >= Tlen.Text) And (Len(T3L2.Text) = 0) Then
'       If IsNumeric(T1L2.Text) = True Then Call AddRingNumber(2, T1L2.Text)
'   End If
TL2CallerID.Enabled = False
End Sub

Private Sub TL3CallerID_Timer()
If Left(T1L3, 4) = "8888" Then
    Exit Sub
    TL3CallerID.Enabled = False
End If

If (Len(T1L3.Text) >= Tlen.Text) Then 'And Len(T2L3.Text) = 0 Then
       If IsNumeric(T1L3.Text) = True Then Call AddRingNumber(3, T1L3.Text)
End If
'ElseIf (Len(T1L3.Text) >= Tlen.Text) And (Len(T3L3.Text) = 0) Then
'       If IsNumeric(T1L3.Text) = True Then Call AddRingNumber(3, T1L3.Text)
'   End If
TL3CallerID.Enabled = False
End Sub

Private Sub TL4CallerID_Timer()
If Left(T1L4, 4) = "8888" Then
    Exit Sub
    TL4CallerID.Enabled = False
End If

If (Len(T1L4.Text) >= Tlen.Text) Then 'And Len(T2L4.Text) = 0 Then
       If IsNumeric(T1L4.Text) = True Then Call AddRingNumber(4, T1L4.Text)
End If
'ElseIf (Len(T1L4.Text) >= Tlen.Text) And (Len(T3L4.Text) = 0) Then
'       If IsNumeric(T1L4.Text) = True Then Call AddRingNumber(4, T1L4.Text)
'   End If
TL4CallerID.Enabled = False
End Sub

Private Sub TToneL1_Timer()
  If Len(T1L1.Text) > 6 Then L1Tone.Text = T1L1.Text
  TToneL1.Enabled = False
End Sub

Private Sub TDetectHangUp1_Timer()

If Len(T1L1.Text) = 0 Then CounterHangUp1 = CounterHangUp1 + 1
If CounterHangUp1 = 3 Then
    L1HangUp.Value = True
        TToneL1.Enabled = True
    TDetectHangUp1 = False
ElseIf CounterHangUp1 = 5 Then
    TDetectHangUp1 = False
End If
End Sub




Private Sub Timer1_Timer()
If FlagAddDataFromCom = True Then Exit Sub
TimeAddData = True
Level1 = MyData
MyData = ""
Level2 = Level2 & Level1
If Len(Level1) > 0 Then List1.AddItem Level1
TimeAddData = False
End Sub


Private Sub TToneL2_Timer()
  If Len(T1L2.Text) > 6 Then L2Tone.Text = T1L2.Text
  TToneL2.Enabled = False
End Sub

Private Sub TToneL3_Timer()
  If Len(T1L3.Text) > 6 Then L3Tone.Text = T1L3.Text
  TToneL3.Enabled = False
End Sub

Private Sub TToneL4_Timer()
  If Len(T1L4.Text) > 6 Then L4Tone.Text = T1L4.Text
  TToneL4.Enabled = False
End Sub

