VERSION 5.00
Begin VB.Form FormDemo 
   Caption         =   "CIDR Sample"
   ClientHeight    =   7800
   ClientLeft      =   120
   ClientTop       =   450
   ClientWidth     =   14235
   LinkTopic       =   "Form1"
   ScaleHeight     =   7800
   ScaleWidth      =   14235
   StartUpPosition =   3  'Windows Default
   Begin VB.ComboBox ComboPlay 
      BeginProperty Font 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   178
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   315
      ItemData        =   "FormMain.frx":0000
      Left            =   12690
      List            =   "FormMain.frx":001F
      Style           =   2  'Dropdown List
      TabIndex        =   6
      Top             =   5625
      Width           =   1380
   End
   Begin VB.ListBox ListDescription 
      BeginProperty Font 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   178
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   3960
      Left            =   165
      TabIndex        =   4
      Top             =   3645
      Width           =   12270
   End
   Begin VB.CommandButton ButtonClearDescription 
      Caption         =   "Clear Description"
      BeginProperty Font 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   178
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   540
      Left            =   12585
      TabIndex        =   3
      Top             =   3615
      Width           =   1380
   End
   Begin VB.ListBox ListLog 
      BeginProperty Font 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   178
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   3375
      Left            =   135
      TabIndex        =   0
      Top             =   75
      Width           =   12300
   End
   Begin VB.CommandButton ButtonClearLog 
      Caption         =   "Clear Log"
      BeginProperty Font 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   178
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   540
      Left            =   12630
      TabIndex        =   2
      Top             =   2850
      Width           =   1380
   End
   Begin VB.CommandButton ButtonInfo 
      Caption         =   "Info"
      BeginProperty Font 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   178
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   540
      Left            =   12645
      TabIndex        =   1
      Top             =   195
      Width           =   1380
   End
   Begin VB.Label LabelPlayLine 
      AutoSize        =   -1  'True
      Caption         =   "Play Line:"
      BeginProperty Font 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   178
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   195
      Left            =   12630
      TabIndex        =   5
      Top             =   5250
      Width           =   690
   End
End
Attribute VB_Name = "FormDemo"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Form_Load()
  If Not CIDR_Load Then
    MsgBox "Cannot load POS_CIDR!"
    AddLog "Cannot load POS_CIDR!"
  Else
    AddLog "POS_CIDR Loaded"
  End If
End Sub

Private Sub ButtonInfo_Click()
  MsgBox CIDR_Info()
End Sub

Private Sub ButtonClearDescription_Click()
  ListDescription.Clear
End Sub

Private Sub ButtonClearLog_Click()
  ListLog.Clear
End Sub

Private Sub ComboPlay_Click()
  CIDR_PlayLine ComboPlay.ListIndex
End Sub

Private Sub AddLog(item As String)
  ListLog.AddItem (Time$ & ": " & item)
End Sub

Private Sub AddDescription(item As String)
  ListDescription.AddItem (Time$ & " " & item)
End Sub

Public Function GenerateFileName(line As Long) As String
  Dim res As String
  res = Replace(Date$, "/", "-") & "-" & Replace(Time$, ":", "-")
  res = App.Path & "\Calls\" & res & "[" & line & "].mp3"
  GenerateFileName = res
End Function

Public Sub CIDR_Event(line As Long, msg As String)
  Dim temp As String
  Dim stopSave As Boolean
  
  AddLog (line & " -> " & msg)
  
  If line = 0 Then  'System event
    temp = Left$(msg, 2)
    If (temp = "SC") Then
      AddDescription "Device Connected"
    ElseIf (temp = "SD") Then
      AddDescription "Device Disconnected"
    End If
  Else    ' Line event
    temp = Left$(msg, 1)
    stopSave = False
    
    If (temp = "C") Then    ' Caller ID
      Dim CallerID As String
      Dim DateTime As String
      CallerID = Mid$(msg, 2, InStr(msg, ",") - 2)
      DateTime = Mid$(msg, InStr(msg, ",") + 1, 8)
      DateTime = Left$(DateTime, 2) & "/" & Mid$(DateTime, 3, 2) & " " & Mid$(DateTime, 5, 2) & ":" & Right$(DateTime, 2)
      AddDescription "[" & line & "] " & "CallerID: " & CallerID & "  DateTime: " & DateTime
      
    ElseIf (temp = "D") Then  ' Key Pressed (Dialed)
      Dim KeyDTMF As String
      KeyDTMF = Mid$(msg, 2, 1)
      AddDescription "[" & line & "] " & "Pressed Key: " & KeyDTMF
      
    ElseIf (temp = "X") Then  ' Line Disconnected
      AddDescription "[" & line & "] " & "Line Disconnected"
      stopSave = True
      
    ElseIf (temp = "Q") Then  ' Device Disconnected
      AddDescription "[" & line & "] " & "Line not available (Device Disconnected)"
      stopSave = True
    
    ElseIf (temp = "F") Then  ' Hook Off
      AddDescription "[" & line & "] " & "Hook Off"
      CIDR_SaveLine line, GenerateFileName(line), ""
    
    ElseIf (temp = "N") Then  ' Hook On
      Dim OffTime As String
      Dim DialedStr As String
      OffTime = Mid$(msg, 2, InStr(msg, "D") - 2)
      DialedStr = Mid$(msg, InStr(msg, "D") + 1)
      AddDescription "[" & line & "] " & "Hook On (OffTime=" & OffTime & "s) (Dialed=" & DialedStr & ")"
      stopSave = True
    
    ElseIf (temp = "R") Then
      Dim RingCount As String
      RingCount = Mid$(msg, 2)
      AddDescription "[" & line & "] " & "Ring (" & RingCount & " times)"
    
    ElseIf (temp = "I") Then
      temp = UCase$(Mid$(msg, 2, 5))
      If (temp = "SAVE ") Then
        Dim fname As String
        fname = Mid$(msg, 7)
        AddDescription "[" & line & "] " & "Saving to file: " & fname
      ElseIf (temp = "SAVES") Then
        AddDescription "[" & line & "] " & "Save Stopped!"
      End If
      
    End If
  
    If stopSave Then
      CIDR_SaveLine line, "", ""
    End If
  
  End If
    
End Sub

