Basic Caller Id program - by Aspen2K

Squirm
03-21-2002, 10:54 AM
Uses MSComm to receive information from the modem, and on those that can, retrieve CallerID information. You need to add an MSComm control on the form called MSComm1 and textboxes named txtname1, txtnmbr1, txttime1 and txtdate1. Enjoy.....

:D

Option Explicit

'' This program was designed to capture incoming caller id info.
'' You must have a caller id compatible modem in order for this
'' to work. If you are not sure if you do or not, open Hyper terminal
'' type AT+VCID=1 If you get an OK message back, your set to go,
'' if you get en ERROR, then your modem does not support Caller ID.
'' If you have questins, comments, you can contact me on the
'' www.visualbasicforum.com website or on IRC DalNet #Extreme-vb
''
'' Thank you - Aspen2K

Dim Inp As String, ds As String
Dim l1 As String, l2 As String, l3 As String, l4 As String
Dim rk As String, sk As String
Dim da As String, ti As String, na As String, nu As String

Private Sub Form_Load()
Show
GetInfo
End Sub

Private Sub GetInfo()
'Set modem commport
MSComm1.CommPort = 1
'Set modem Baud rate,Parity,Data bit, stop bit
MSComm1.settings = "9600,N,8,1"
MSComm1.InputLen = 0
'Open port
MSComm1.PortOpen = True
'Sends Caller ID string to the modem
MSComm1.Output = "AT+VCID=1" + Chr$(13)

waitagain:

'This line below will take you to the WF sub(wait for data)
'In my case I am waiting for ("DATE") because this will be
'the first section of data to be displayed when a call comes in.
'Look in the OnComm sub to see what incoming data looks like
wf ("DATE")
'After the call comes in do some instringing
'and some midstringing and wala, you have your
'Caller Id info in a box. Im sure the lines
'below are really ugly. But hey, works for me :)
l1 = InStr(1, Inp, "DATE =")
l2 = InStr(1, Inp, "TIME =")
l3 = InStr(1, Inp, "NAME =")
l4 = InStr(1, Inp, "NMBR =")
rk = InStr(l3, Inp, Chr$(13))
sk = InStr(l4, Inp, Chr$(13))
da = Mid(Inp, l1 + 7, 4)
ti = Mid(Inp, l2 + 7, 4)
na = Mid(Inp, l3 + 7, rk - (l3 + 7))
nu = Mid(Inp, l4 + 7, sk - (l4 + 7))

txtname1.Text = na
txtnmbr1.Text = nu
txttime1.Text = ti
txtdate1.Text = da

'After all this call stuff, refresh the callerd id string.
MSComm1.Output = "AT+VCID=1" + Chr$(13)
'Takes to back to pretty much the top of this sub just
'to wait for another call!
GoTo waitagain

End Sub

Private Sub wf(w As String)
'Input Variable
Inp = ""
'What this does is waits for a call. When ever a call
'comes in, the data that is put into the buffer
'starts with DATE so it is looking instr(inp,w)
While InStr(Inp, w) = 0
DoEvents
Wend
End Sub

Private Sub MSComm1_OnComm()
'When info comes into the buffer, give it a
'name and debug.print.
If MSComm1.InBufferCount > 0 Then ds = MSComm1.Input
If ds <> "" Then Inp = Inp & ds
Debug.Print ds
'This is what the imcoming info will look like
'RING
'Date = 0321
'Time = 1847
'NAME = Callers Name
'NMBR = 1234567890
'AT+VCID=1
'OK
End Sub

Courtesy Aspen2K :)

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum