Solved

Dial Modem

Posted on 1998-06-09
1
482 Views
Last Modified: 2012-05-07
Does anyone know how to dial a modem on demand and hang up when the time comes?
0
Comment
Question by:majestic
1 Comment
 
LVL 9

Accepted Solution

by:
Dalin earned 100 total points
ID: 1462967
majestic,
Try the following code.
If you have any questions, let me know.
Regards
Dalin



       Private Sub Dial(Number$)
           Dim DialString$, FromModem$
           Dim StopString As String
           Dim Delay As Double

           '--- AT is the Hayes compatible ATTENTION command an is required to send commands to the modem.
           '--- DT means "Dial Tone" - The Dial command, using touch tones as opposed to pulse (DP = Dial Pulse)
           '--- PhoneNumbers$(Index) is the phone number of the person you're dialing
           '--- A semicolon tells the modem to return to command mode after dialing (important)
           '--- A Carriage return, Chr$(13), is required when sending commands to the modem.
           DialString$ = "ATX4&D2DT" + Number$ + ";" + Chr$(13)
           StopString = "ATH0" + Chr$(13)
           '-- Comm port settings
           Comm1.Settings = "300,N,8,1"
           
           '-- Open the comm port
           On Error Resume Next
           Comm1.PortOpen = True
           If Err Then
              MsgBox "COM1: not available. Change the CommPort property to another port."
              Exit Sub
           End If
           
           '-- Flush the input buffer
           Comm1.InBufferCount = 0
           
           '-- Dial the number
           Comm1.Output = DialString$
           
           '-- Wait for "OK" to come back from the modem
           Do
              DoEvents
              '-- If there is data in the buffer, then read it.
              If Comm1.InBufferCount Then
                 FromModem$ = FromModem$ + Comm1.Input
                 '-- Check for "OK"
                 If InStr(FromModem$, "OK") Then
                    '-- Notify the user to pick up the phone
                    FromModem = ""
                    Beep
                    MsgBox "Please pick up the phone and either press Enter, or click OK"
                    Exit Do
                 ElseIf InStr(FromModem$, "NO DIAL TONE") Or InStr(FromModem$, "NO DIALTONE") Then
                    FromModem = ""
                    Beep
                    MsgBox "Dialtone not detected.  Please check the telephone connection."
                    CancelFlag = True
                    Exit Do
                 End If
              End If
               
              '-- Was Cancel pressed?
              If CancelFlag Then
                 CancelFlag = False
                 Exit Do
              End If
           Loop

           '-- Disconnect the modem
           Comm1.Output = StopString
           
           '-- Close the port
           Delay = Timer
           While Delay + 1 > Timer
               DoEvents
              '-- If there is data in the buffer, then read it.
              If Comm1.InBufferCount Then
                 FromModem$ = FromModem$ + Comm1.Input
              End If
           Wend
           Comm1.DTREnable = False    'belts and suspenders
           Delay = Timer              'disconnect.  If StopString
           While Delay + 1 > Timer    'worked, this isn't needed.
               DoEvents
           Wend
           Comm1.DTREnable = True
           Comm1.PortOpen = False
       End Sub
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Extract Data and filename Macro 20 99
Use Multiple Forms 4 38
Problem to skip loop 6 49
SSRS expression Issue finding a string 10 51
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now