Andrew Bedno    Andrew@Bedno.com • 773-213-4578
 History   Kudos   Samples 

VB
1996 - Ongoing  (28 Years 4 Months)
VB

Windows Telephone Dialer

Autodial a phone number by double clicking a program manager icon.
Windows program written in Visual Basic, demonstrates serial port access and modem control.
Also download my library of Visual Basic routines and utilities (and runtime files).


Attribute VB_Name = "autodial_util"
Option Explicit

' Autodial - Andrew Bedno - 1995.07.28
' Dials a phone number specified on the command line,
' then prompts the user to pick up the phone.
' Use to make speed dial icons.

Public Const ProgName = "AUTODIAL"

Public DialNum As String

Public DialPort As String
Public DialPrefix As String
Public DialCurrAC As String
Public DialSpeed As String
Public DialPause1 As Integer
Public DialPause2 As Integer
Public DialModemInit As String
Public DialModemReset As String
Public DialAbort As Integer

Public Declare Function GetPrivateProfileString Lib "Kernel" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Integer, ByVal lpFileName As String) As Integer
Public Declare Function WritePrivateProfileString Lib "Kernel" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As String, ByVal lplFileName As String) As Integer

Private Sub Dial()
    Dim OpenCom As Integer
    Dim ComResult As Integer
    Dim ModemCmd As String
    DialAbort = False
    If Trim$(DialNum) = "" Then
        MsgBox "No phone number specified."
        Exit Sub
    End If
    DialPort = UCase$(Trim$(DialPort))
    If (Left(DialPort, 3) <> "COM") Or (Len(DialPort) <> 4) Then
        MsgBox "Port must be Com1..Com4."
        Exit Sub
    End If
    If (Right(DialPort, 1) > "4") Or (Right(DialPort, 1) < "1") Then
        MsgBox "Port must be Com1..Com4."
        Exit Sub
    End If
    autodial.ComTool.CommPort = Asc(Right(DialPort, 1)) - Asc("0")
    autodial.ComTool.Settings = DialSpeed & ",N,8,1"
    autodial.ComTool.InputLen = 0
    autodial.ComTool.PortOpen = True
    ' Strip leading 1, strip leading current area code, add prefix.
    If Left(DialNum, Len(DialPrefix)) = DialPrefix Then
        DialNum = Right(DialNum, Len(DialNum) - Len(DialPrefix))
    End If
    If Left(DialNum, 1) = "1" Then
        DialNum = Right(DialNum, Len(DialNum) - 1)
    End If
    If Left(DialNum, Len(DialCurrAC)) = DialCurrAC Then
        DialNum = Right(DialNum, Len(DialNum) - Len(DialCurrAC))
    End If
    DialNum = DialPrefix & DialNum
    ' Initialize if necessary.
    If Trim$(DialModemInit) <> "" Then
        ModemCmd = DialModemInit & Chr(13)
        autodial.ComTool.Output = ModemCmd
        autodial.CallTimer.Interval = 1000
        autodial.CallTimer.Enabled = True
        While autodial.CallTimer.Enabled And (Not DialAbort)
            DoEvents
        Wend
    End If
    ' Dial the number.
    If Not DialAbort Then
        ModemCmd = "ATDT" + DialNum & Chr(13)
        autodial.txtDial.Caption = DialNum
        autodial.ComTool.Output = ModemCmd
        ' Pause for dial.
        If DialPause1 < 0 Then DialPause1 = 0
        If DialPause1 > 30 Then DialPause1 = 30
        autodial.CallTimer.Interval = DialPause1 * 1000
        autodial.CallTimer.Enabled = True
        While autodial.CallTimer.Enabled And (Not DialAbort)
            DoEvents
        Wend
        ' Display pick up phone message.
        autodial.msgPickUp.Visible = True
        autodial.msgPickUp.ZOrder 0
        ' Pause for pickup.
        If DialPause2 < 0 Then DialPause2 = 0
        If DialPause2 > 30 Then DialPause2 = 30
        autodial.CallTimer.Interval = DialPause2 * 1000
        autodial.CallTimer.Enabled = True
        While autodial.CallTimer.Enabled And (Not DialAbort)
            DoEvents
        Wend
    End If
    ' Reset (hang up) if necessary.
    If Trim$(DialModemReset) <> "" Then
        ModemCmd = DialModemReset & Chr(13)
        autodial.ComTool.Output = ModemCmd
    End If
    ' Close port.
    autodial.ComTool.PortOpen = False
    Exit Sub
End Sub

Private Sub DoHelp()
    Dim HelpMsg As String
    Dim NL As String
    Dim TabChr As String
    TabChr = Chr(9)
    NL = Chr(13) & Chr(10)
    HelpMsg = ProgName & " - Ver 1.0 Rev 1995.02.26" & NL
    HelpMsg = HelpMsg & "By Andrew Bedno - Chicago" & NL
    HelpMsg = HelpMsg & NL
    HelpMsg = HelpMsg & "Specify phone number on command line." & NL
    HelpMsg = HelpMsg & TabChr & "Leading 1 will be stripped." & NL
    HelpMsg = HelpMsg & TabChr & "Leading area code stripped if same as current." & NL
    HelpMsg = HelpMsg & TabChr & "Leading 1 added if still over seven digits." & NL
    HelpMsg = HelpMsg & TabChr & "Leading prefix added." & NL
    HelpMsg = HelpMsg & "Reads " & ProgName & ".INI for settings:" & NL
    HelpMsg = HelpMsg & TabChr & "[" & ProgName & "]" & NL
    HelpMsg = HelpMsg & TabChr & "PORT=Com1/Com2/Com3/Com4" & NL
    HelpMsg = HelpMsg & TabChr & "SPEED=9600/2400/..." & NL
    HelpMsg = HelpMsg & TabChr & "CURRAC=Area code of current location." & NL
    HelpMsg = HelpMsg & TabChr & "PREFIX=Outgoing line prefix." & NL
    HelpMsg = HelpMsg & TabChr & "PAUSE1=Seconds to dial." & NL
    HelpMsg = HelpMsg & TabChr & "PAUSE2=Seconds before hangup." & NL
    HelpMsg = HelpMsg & TabChr & "MODEMINIT=Modem pre-dial init string." & NL
    HelpMsg = HelpMsg & TabChr & "MODEMRESET=Modem hang up string." & NL
    HelpMsg = HelpMsg & "Any keypress or click interrupts."
    MsgBox HelpMsg
    End
End Sub

Private Function FixTrim(ByVal In_Str As String) As String
    Dim FixOut As String
    Dim FixLoop As Integer
    FixOut = ""
    For FixLoop = 1 To Len(In_Str)
        If (Mid$(In_Str, FixLoop, 1) >= " ") And (Mid$(In_Str, FixLoop, 1) <= Chr(127)) Then
            FixOut = FixOut & Mid$(In_Str, FixLoop, 1)
        End If
    Next FixLoop
    FixTrim = Trim$(FixOut)
End Function

Sub AutoDial_Main()
    Dim IniFileName As String
    Dim IniAppName As String
    Dim IniKeyName As String
    Dim IniDefault As String
    Dim IniReadStr As String * 30  'make fixed length because of DLL return
    Dim IniReadSize As Integer
    Dim IniResult As Integer
    IniAppName = ProgName
    IniFileName = ProgName & ".INI"
    IniReadSize = 31
    IniKeyName = "PORT"
    IniDefault = "COM2"
    IniReadStr = ""
    IniResult = GetPrivateProfileString(IniAppName, IniKeyName, IniDefault, IniReadStr, IniReadSize, IniFileName)
    DialPort = FixTrim$(IniReadStr)
    If Trim$(DialPort) = "" Then
        MsgBox "Cannot find initialization file."
        End
    End If
    IniKeyName = "SPEED"
    IniDefault = "9600"
    IniReadStr = ""
    IniResult = GetPrivateProfileString(IniAppName, IniKeyName, IniDefault, IniReadStr, IniReadSize, IniFileName)
    DialSpeed = FixTrim$(IniReadStr)
    IniKeyName = "PREFIX"
    IniDefault = ""
    IniReadStr = ""
    IniResult = GetPrivateProfileString(IniAppName, IniKeyName, IniDefault, IniReadStr, IniReadSize, IniFileName)
    DialPrefix = FixTrim$(IniReadStr)
    IniKeyName = "CURRAC"
    IniDefault = ""
    IniReadStr = ""
    IniResult = GetPrivateProfileString(IniAppName, IniKeyName, IniDefault, IniReadStr, IniReadSize, IniFileName)
    DialCurrAC = FixTrim$(IniReadStr)
    IniKeyName = "PAUSE1"
    IniDefault = "2"
    IniReadStr = ""
    IniResult = GetPrivateProfileString(IniAppName, IniKeyName, IniDefault, IniReadStr, IniReadSize, IniFileName)
    DialPause1 = Val(FixTrim$(IniReadStr))
    IniKeyName = "PAUSE2"
    IniDefault = "5"
    IniReadStr = ""
    IniResult = GetPrivateProfileString(IniAppName, IniKeyName, IniDefault, IniReadStr, IniReadSize, IniFileName)
    DialPause2 = Val(FixTrim$(IniReadStr))
    IniKeyName = "MODEMINIT"
    IniDefault = ""
    IniReadStr = ""
    IniResult = GetPrivateProfileString(IniAppName, IniKeyName, IniDefault, IniReadStr, IniReadSize, IniFileName)
    DialModemInit = FixTrim$(IniReadStr)
    IniKeyName = "MODEMRESET"
    IniDefault = "+++~~~ATH"
    IniReadStr = ""
    IniResult = GetPrivateProfileString(IniAppName, IniKeyName, IniDefault, IniReadStr, IniReadSize, IniFileName)
    DialModemReset = FixTrim$(IniReadStr)
    If (Trim$(Command$) = "") Or (Trim$(Command$) = "?") Then
        DoHelp
        End
    End If
    autodial.Show
    DialNum = FixTrim$(Command$)
    Dial
    End
End Sub


 DOWNLOAD         < NEWER    OLDER >