Arrays of a Different Color

Software Careers Fall 1997 Dr. Dobb's Journal

by Al Williams


Listing One
VERSION 5.00
Begin VB.Form Form1
   Caption         =   "Dialer"
   ClientHeight    =   3195
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   5490
   LinkTopic       =   "Form1"
   ScaleHeight     =   3195
   ScaleWidth      =   5490
   StartUpPosition =   3  'Windows Default
   Begin VB.CommandButton Dial
      Caption         =   "&Dial"
      Height          =   375
      Left            =   120
      TabIndex        =   14
      Top             =   720
      Width           =   855
   End
   Begin VB.CommandButton Clear
      Caption         =   "&Clear"
      Height          =   375
      Left            =   120
      TabIndex        =   13
      Top             =   120
      Width           =   855
   End
   Begin VB.CommandButton Key1
      Caption         =   "#"
      Height          =   375
      Index           =   11
      Left            =   2880
      TabIndex        =   12
      Top             =   2520
      Width           =   495
   End
   Begin VB.CommandButton Key1
      Caption         =   "0"
      Height          =   375
      Index           =   0
      Left            =   2280
      TabIndex        =   11
      Top             =   2520
      Width           =   495
   End
   Begin VB.CommandButton Key1
      Caption         =   "*"
      Height          =   375
      Index           =   10
      Left            =   1680
      TabIndex        =   10
      Top             =   2520
      Width           =   495
   End
   Begin VB.CommandButton Key1
      Caption         =   "9"
      Height          =   375
      Index           =   9
      Left            =   2880
      TabIndex        =   9
      Top             =   1920
      Width           =   495
   End
   Begin VB.CommandButton Key1
      Caption         =   "8"
      Height          =   375
      Index           =   8
      Left            =   2280
      TabIndex        =   8
      Top             =   1920
      Width           =   495
   End
   Begin VB.CommandButton Key1
      Caption         =   "7"
      Height          =   375
      Index           =   7
      Left            =   1680
      TabIndex        =   7
      Top             =   1920
      Width           =   495
   End
   Begin VB.CommandButton Key1
      Caption         =   "6"
      Height          =   375
      Index           =   6
      Left            =   2880
      TabIndex        =   6
      Top             =   1320
      Width           =   495
   End
   Begin VB.CommandButton Key1
      Caption         =   "5"
      Height          =   375
      Index           =   5
      Left            =   2280
      TabIndex        =   5
      Top             =   1320
      Width           =   495
   End
   Begin VB.CommandButton Key1
      Caption         =   "4"
      Height          =   375
      Index           =   4
      Left            =   1680
      TabIndex        =   4
      Top             =   1320
      Width           =   495
   End
   Begin VB.CommandButton Key1
      Caption         =   "3"
      Height          =   375
      Index           =   3
      Left            =   2880
      TabIndex        =   3
      Top             =   720
      Width           =   495
   End
   Begin VB.CommandButton Key1
      Caption         =   "2"
      Height          =   375
      Index           =   2
      Left            =   2280
      TabIndex        =   2
      Top             =   720
      Width           =   495
   End
   Begin VB.CommandButton Key1
      Caption         =   "1"
      Height          =   375
      Index           =   1
      Left            =   1680
      TabIndex        =   1
      Top             =   720
      Width           =   495
   End
   Begin VB.TextBox TelNo
      Height          =   285
      Left            =   1200
      TabIndex        =   0
      Top             =   120
      Width           =   2655
   End
   Begin VB.Frame Frame1
      Caption         =   "Speed Dial"
      Height          =   2775
      Left            =   3960
      TabIndex        =   15
      Top             =   360
      Width           =   1455
      Begin VB.CommandButton Add
         Caption         =   "&Add"
         Height          =   375
         Left            =   120
         TabIndex        =   17
         Top             =   240
         Width           =   1215
      End
      Begin VB.CommandButton Speed
         Caption         =   "Speed"
         Height          =   375
         Index           =   0
         Left            =   120
         TabIndex        =   16
         Top             =   840
         Visible         =   0   'False
         Width           =   1215
      End
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim SpeedBtns As Integer  ' # of speed buttons
Dim Digitcount As Integer ' # of digits entered

' Sets focus back to edit box
Private Sub Refocus()
TelNo.SetFocus
TelNo.SelStart = Len(TelNo.Text)
End Sub

Private Sub Add_Click()
If SpeedBtns = 5 Then  ' maximum speed dials
  Beep
  Exit Sub
End If
If (SpeedBtns <> 0) Then
    Load Speed(SpeedBtns)
    Speed(SpeedBtns).Top = Speed(SpeedBtns - 1).Top + Speed(0).Height + 10
    Speed(SpeedBtns).Left = Speed(0).Left
End If
Speed(SpeedBtns).Caption = TelNo.Text
Speed(SpeedBtns).Visible = True
SpeedBtns = SpeedBtns + 1
Refocus
End Sub


Private Sub Clear_Click()
TelNo.Text = ""
Digitcount = 0
Refocus
End Sub

Private Sub Dial_Click()
MsgBox "Dialed " & TelNo.Text
Clear_Click
End Sub

Private Sub Key1_Click(Index As Integer)
Dim key
If Index = 10 Then  ' Convert *
  key = "*"
ElseIf Index = 11 Then  ' Convert #
  key = "#"
Else
  key = CStr(Index)  ' Just get #
End If
TelNo.Text = TelNo.Text & key
Digitcount = Digitcount + 1
' Half-hearted attempt to format phone number
If Digitcount = 3 Then TelNo.Text = TelNo.Text & "-"

Refocus
End Sub

' Do speed dial
Private Sub Speed_Click(Index As Integer)
TelNo.Text = Speed(Index).Caption
Dial_Click
End Sub

' Keyboard input
Private Sub TelNo_KeyPress(key As Integer)
If key >= Asc("0") And key <= Asc("9") Then
 n = TelNo.SelStart
 l = Len(TelNo.Text)
 If l = 3 Then
   TelNo.Text = TelNo.Text & "-"
   If n = l Then n = n + 1
 ElseIf l = 8 Then
   TelNo.Text = Left(TelNo.Text, 7) & "-" & Right(TelNo.Text, 1)
   If n > 7 Then n = n + 1
 End If
 Digitcount = Digitcount + 1
 TelNo.SelStart = n
End If
End Sub

Listing Two
Form1 = 53, 18, 559, 342, , 69, 131, 490, 448, 

Listing Three
Type=Exe
Form=Dialer.frm
Reference=*\G{00020430-0000-0000-C000-         000000000046}#2.0#0#C:\WINDOWS\SYSTEM\STDOLE2.TLB#OLE Automation
IconForm="Form1"
Startup="Form1"
Command32=""
Name="Project1"
HelpContextID="0"
CompatibleMode="0"
MajorVer=1
MinorVer=0
RevisionVer=0
AutoIncrementVer=0
ServerSupportFiles=0
VersionCompanyName="AWC"
CompilationType=-1
OptimizationType=0
FavorPentiumPro(tm)=0
CodeViewDebugInfo=0
NoAliasing=0
BoundsCheck=0
OverflowCheck=0
FlPointCheck=0
FDIVCheck=0
UnroundedFP=0
StartMode=0
Unattended=0
ThreadPerObject=0
MaxNumberOfThreads=1
End Listings

Return to Article

DDJ