To begin, open Visual Basic 6 and choose Standard EXE as the type of project.
Then add a label to the form and change its properties as shown in the following screenshot.
The most important part of this program is the use of the MSComm component. We'll need to add the component to the project. To do this, click the Project menu and choose components.
Then check the Microsoft Comm Control 6.0 and click okay.
Now there will be a small yellow telephone icon in the toolbox.
Double click the telephone icon to add the component to the form. The icon will not be visible at runtime; it shows up on the form to allow you to set properties of the component using the IDE.
Double click on the form to bring up the code for the form. By default the Form_load Sub's skeleton will be written.
Copy and paste the following code into the code area. (Overwrite the contents)
Public Call_Name As String
Public Call_Number As String
Private Sub Form_Load()
With MSComm1
.Settings = "9600, N, 8, 1" '// Baud, Parity, Data Bits, Stop Bits
.CommPort = 2 '// Change to the port of your modem
If .PortOpen = False Then '// If the port is not already open
.PortOpen = True '// open it
End if
.RThreshold = 0
.InputLen = 0
.Output = "AT#CID=1" & Chr(13) '// Send the modem the
'// appropriate AT command
'// to enable the modem to
'// sit and wait for
'// incoming calls and capture
'// the caller id information
'// Check the modem's documentation
'// for the correct string
End With
End Sub
Private Sub Form_Unload(Cancel As Integer)
MSComm1.PortOpen = False '// Close the port when the
'// program is closed
End Sub
Private Sub MSComm1_OnComm()
Dim Buffer As String '// Will hold the string
'// from the modem
'// I was having problems dealing with
'// the returns and line feeds so I deleted
'// them from the Buffer
Buffer = Replace(MSComm1.Input, Chr(13), "")
Buffer = Replace(Buffer, Chr(10), "")
GetCallerInfo (Buffer)
End Sub
Private Sub GetCallerInfo(Caller_Id_string As String)
If InStr(Caller_Id_string, "NAME") > 0 Then
Call_Name = Mid(Caller_Id_string, (InStr(Caller_Id_string, "NAME = ") + 7), _
((InStr(Caller_Id_string, "NMBR = ") - 7) - InStr(Caller_Id_string, "NAME = ")))
End If
If InStr(Caller_Id_string, "NMBR") > 0 Then
Call_Number = Mid(Caller_Id_string, (InStr(Caller_Id_string, "NMBR = ") + 7))
End If
If Len(Call_Name) > 1 Or Len(Call_Number) > 1 Then
Call Database_Update()
End If
End Sub
Private Function Database_Update()
Dim Command_Text As String
Command_Text = "Insert Into tbl_Caller_Id (Call_Name, Call_Number)" & _
"Values ('" & Call_Name & "', '" & Call_Number & "')"
Dim myConnection As New ADODB.Connection
myConnection.Open "Driver={SQL Server};" & _
"Server=localhost;" & _
"Database=mydb;" & _
"Uid=;" & _
"Pwd=;"
myConnection.Execute (Command_Text)
myConnection.Close
Call_Name = "" '// Set the values back to nothing
Call_Number = ""
End Function
All that's left is to go to the file menu and choose the make .exe option.