СообЧа > База Знаний > Программирование > Visual Basic

Вопрос

Подскажите, как сделать номеронабиратель, чтоб можно было позвонить модемом?

Ответ

Option Explicit
DefInt A-Z
Dim CancelFlag As Boolean
Private Sub CancelButton_Click()
CancelFlag = True
CancelButton.Enabled = False
End Sub
Private Sub DialButton_Click()
Dim Number$
On Error GoTo Err_click
Number$ = Selection.Value
If Number$ = "" And Not IsNumeric(Number$) Then Exit Sub
DialButton.Enabled = False
CancelButton.Enabled = True
Status = "Dialing — " + Number$
Dial Number$
DialButton.Enabled = True
CancelButton.Enabled = False
Err_click:
End Sub
Private Sub Dial(Number$)
Dim DialString$, FromModem$, dummy
' AT is the Hayes compatible ATTENTION command and is required to send commands
to the modem.
' DT means "Dial Tone." The Dial command uses touch tones, as opposed to pulse
(DP = Dial Pulse).
' Numbers$ is the phone number being dialed.
' A semicolon tells the modem to return to command mode after dialing (important).
' A carriage return, vbCr, is required when sending commands to the modem.
DialString$ = "ATDP" + Number$ + ";" + vbCr
' Communications port settings.
' Assuming that a mouse is attached to COM1, CommPort is set to 2
MSComm1.CommPort = 4
MSComm1.Settings = "9600,N,8,1"
' Open the communications port.
On Error Resume Next
MSComm1.PortOpen = True
If Err Then
MsgBox "COM2: not available. Change the CommPort property to another port."
Exit Sub
End If
' Flush the input buffer.
MSComm1.InBufferCount = 0
' Dial the number.
MSComm1.Output = DialString$
' Wait for "OK" to come back from the modem.
Do
dummy = DoEvents()
DoEvents
' If there is data in the buffer, then read it.
If MSComm1.InBufferCount Then
FromModem$ = FromModem$ + MSComm1.Input
' Check for "OK".
If InStr(FromModem$, "OK") Then
' Notify the user to pick up the phone.
Beep
MsgBox "Please pick up the phone and either press Enter or click OK"
Exit Do
' Status = "Dialing — " + FromModem$ + " — " + Number$
ElseIf InStr(FromModem$, "BUSY") Then
Disconnect
Call Dial(Number$)
Exit Sub
ElseIf InStr(FromModem$, "Error") Then
MsgBox "Error " + FromModem$
Exit Do
End If
End If
' Did the user choose Cancel?
If CancelFlag Then
CancelFlag = False
Exit Do
End If
Loop
Disconnect

End Sub
Private Sub DialButton_GotFocus()
Cells(Selection.Row, Selection.Column).Select
End Sub
Private Sub Status_Click()
On Error Resume Next
DialButton.Enabled = True
'QuitButton.Enabled = False
CancelButton.Enabled = True
' Disconnect the modem.
MSComm1.Output = "ATH" + vbCr
' Close the port.
MSComm1.PortOpen = False
End Sub
Public Sub Disconnect()
' Disconnect the modem.
MSComm1.Output = "ATH" + vbCr
' Close the port.
MSComm1.PortOpen = False
End Sub


Все это вставь в лист Excel. Окно открывается, если кликнуть на него в среде VB. На этом листе размести кнопки «CancelButton», «DialButton»; лабел «Status» и MSComm «MSComm1»
Потом пиши номер телефона в ячейке и дави кнопку DialButton.



Copyright © 2000-2004 Сообщество Чайников
Контактная информация