Está en la página 1de 3

'==================================================================================

==================
'- DIAL A TELEPHONE NUMBER VIA MODEM
'- Brian Baulsom November 2007
'==================================================================================
==================
Option Explicit
Dim MSComm1 As Object
Dim MyNumber As String
Dim DialString As String

'==================================================================================
==================
'- MAIN ROUTINE
'==================================================================================
==================
Sub TEST()
'- Telephone number
MyNumber = "123" ' UK talking clock
DIAL MyNumber
End Sub
'---------- END OF MAIN ROUTINE
------------------------------------------------------------------

'==================================================================================
==================
'- SUBROUTINE : DIAL THE NUMBER
'==================================================================================
==================
Private Sub DIAL(Num As String)
Dim DialString As String
Dim FromModemString As String
Dim rsp

'----------------------------------------------------------------------------------
--------------
'- COM3 setup
Set MSComm1 = CreateObject("MSCommLib.MSComm")
MSComm1.CommPort = 3 ' CHANGE IF REQUIRED
MSComm1.Settings = "9600,N,8,1"

'----------------------------------------------------------------------------------
--------------
'- TEST COM LINK
On Error Resume Next
MSComm1.PortOpen = True
If Err.Number <> 0 Then
MsgBox "(COM3 not available)"
Exit Sub
End If
On Error GoTo 0

'----------------------------------------------------------------------------------
--------------
'- DIAL NUMBER
DialString = "ATDT" + Num + ";" + vbCr
MSComm1.Output = DialString

'----------------------------------------------------------------------------------
--------------
'- WAIT FOR MODEM RESPONSE
Do
DoEvents
If MSComm1.InBufferCount Then
FromModemString = FromModemString + MSComm1.Input

'----------------------------------------------------------------------------------
--------------
' Check for "OK". Prompt user to pick up phone
If InStr(FromModemString, "OK") Then
rsp = MsgBox("OK to get call or Cancel", vbOKCancel)
If rsp = vbCancel Then Exit Do
End If
End If
Loop

'----------------------------------------------------------------------------------
--------------
'- FINISH. DISCONNECT MODEM
MSComm1.Output = "ATH" + vbCr
MSComm1.PortOpen = False
End Sub
'==================================================================================
=================
------------
Hi Brian
Thanks very much for putting so much effort into helping!
Before I actually got to see your latest post, I'd begun to investigate
hyperterminal. I've wanted to try this for a while, and decided to have a bash.
This was actually a bonus because I've not used SendKeys before either, so it's
been a great learning opportunity.
My code calls my phone_dialer function, which shells hyperterminal, passes the
phone number to it, as a string, then gives it time to dial (and the user time to
pick up the phone line), before finally disconnecting hyperterminal, and closing it
down.
I'm posting the code here, in case anyone else wishes to do the same as I have.
Code:
Function phone_dialer(phone_number As String)
Shell ("C:\Program Files\Windows NT\hypertrm.exe"), 0
SendKeys "%{F4}"
SendKeys "ATDT" & phone_number & "~", True
Application.Wait (Now() + TimeValue("00:00:10"))
SendKeys "%CD", True
'Application.Wait (Now() + TimeValue("00:00:4"))
SendKeys "%{F4}", True
End Function
If anyone does wish to use it, then the file path may, of course, need to be
changed, the "Wait" time values for different modems may need changing, and for
interest's sake, if the user wishes to see the application in progress, change the
0 at the end of the first line to a 1 thus:
Code:
Shell ("C:\Program Files\Windows NT\hypertrm.exe"), 1
There are 2 things which you may be able to comment on Brian:
1. So far, Hyperterminal always opens with a "New Connection" window, (which is
quite annoying, as we're not wishing to save a new connection), hence the second
line in my code:
Code:
SendKeys "%{F4}"
....which is to close this window. The trouble is, even with the application
hidden, this window still flashes up on the screen momentarily before the code
closes it, and I'd like to overcome this to make it a little neater.
2. Using the SendKeys command
"%{F4}"
(at least I think it's that one that's doing it) sometimes (but not every time)
puts the keyboard number lock off, which is also very annoying, as my programme
deals mostly with data entry!

Any thoughts gratefully received.

You'll be pleased to know that I'm still going to investigate your MSCOMM32.OCX
idea, as once it's in place, I think it'll perhaps be a better long term telephony
solution, but as my present programme's for some friends who've got their own
machines, and will undoubtedly want to run it on other machines as well, I need to
use something which is readily available to all Windows OS PCs, and I think
hyperterminal probably is. Mind you - that having been said, one of the machines is
a Vista machine, so I'm now going to get on the phone to see if this one even HAS
Hyperterminal on it - OR an internal modem!.........There's always something else
isn't there?!!

Thanks again for your efforts to-date.

All the best

También podría gustarte