• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 355
  • Last Modified:

Telephone Buttons

What is the code for creating buttons, like the ones on a telephone, so that when pressed once they put 2 into text1.text, then when clicked twice puts a, then when e clicks puts b, and on 4 click puts c in the text field. Also when pressed on the next button, that it moves on another character
0
Warsteiner99
Asked:
Warsteiner99
  • 4
  • 2
1 Solution
 
Erick37Commented:
Usually, the program knows when to expect alpha characters and then you can use a 2 digit code to input characters.  e.g. in alpha mode the first digit entered is the position of the letter (1-4) and the second digit is the button where the number is located.  So, to enter the letter "a," the user presses 1 (for position 1) then 2 (the letter "a" is on the 2 button).
0
 
mcriderCommented:
Try this code...

Start notepad and copy the following code into notepad, the save it as "Phone.frm".  Make sure you use the qoutes when you save, otherwise the file will be called Phone.frm.txt and you will have to rename it.

Start Visual basic and add Phone.frm to the project.

Set the startup form to be Phone.frm and run the program... Click away!


Cheers!


THE CODE... COPY EVERYTHING BELOW THE LINE:

--------------------------------------------
VERSION 5.00
Begin VB.Form Form1
   Caption         =   "Form1"
   ClientHeight    =   3450
   ClientLeft      =   5445
   ClientTop       =   1590
   ClientWidth     =   3255
   LinkTopic       =   "Form1"
   ScaleHeight     =   3450
   ScaleWidth      =   3255
   Begin VB.TextBox Text1
      Height          =   375
      Left            =   240
      TabIndex        =   12
      Text            =   "Text1"
      Top             =   360
      Width           =   2895
   End
   Begin VB.CommandButton Command1
      Caption         =   "Command1"
      Height          =   495
      Index           =   11
      Left            =   1920
      Style           =   1  'Graphical
      TabIndex        =   11
      Top             =   2520
      Width           =   615
   End
   Begin VB.CommandButton Command1
      Caption         =   "Command1"
      Height          =   495
      Index           =   10
      Left            =   1320
      Style           =   1  'Graphical
      TabIndex        =   10
      Top             =   2520
      Width           =   615
   End
   Begin VB.CommandButton Command1
      Caption         =   "Command1"
      Height          =   495
      Index           =   9
      Left            =   720
      Style           =   1  'Graphical
      TabIndex        =   9
      Top             =   2520
      Width           =   615
   End
   Begin VB.CommandButton Command1
      Caption         =   "Command1"
      Height          =   495
      Index           =   8
      Left            =   1920
      Style           =   1  'Graphical
      TabIndex        =   8
      Top             =   2040
      Width           =   615
   End
   Begin VB.CommandButton Command1
      Caption         =   "Command1"
      Height          =   495
      Index           =   7
      Left            =   1320
      Style           =   1  'Graphical
      TabIndex        =   7
      Top             =   2040
      Width           =   615
   End
   Begin VB.CommandButton Command1
      Caption         =   "Command1"
      Height          =   495
      Index           =   6
      Left            =   720
      Style           =   1  'Graphical
      TabIndex        =   6
      Top             =   2040
      Width           =   615
   End
   Begin VB.CommandButton Command1
      Caption         =   "Command1"
      Height          =   495
      Index           =   5
      Left            =   1920
      Style           =   1  'Graphical
      TabIndex        =   5
      Top             =   1560
      Width           =   615
   End
   Begin VB.CommandButton Command1
      Caption         =   "Command1"
      Height          =   495
      Index           =   4
      Left            =   1320
      Style           =   1  'Graphical
      TabIndex        =   4
      Top             =   1560
      Width           =   615
   End
   Begin VB.CommandButton Command1
      Caption         =   "Command1"
      Height          =   495
      Index           =   3
      Left            =   720
      Style           =   1  'Graphical
      TabIndex        =   3
      Top             =   1560
      Width           =   615
   End
   Begin VB.CommandButton Command1
      Caption         =   "Command1"
      Height          =   495
      Index           =   2
      Left            =   1920
      Style           =   1  'Graphical
      TabIndex        =   2
      Top             =   1080
      Width           =   615
   End
   Begin VB.CommandButton Command1
      Caption         =   "Command1"
      Height          =   495
      Index           =   1
      Left            =   1320
      Style           =   1  'Graphical
      TabIndex        =   1
      Top             =   1080
      Width           =   615
   End
   Begin VB.CommandButton Command1
      Caption         =   "Command1"
      Height          =   495
      Index           =   0
      Left            =   720
      Style           =   1  'Graphical
      TabIndex        =   0
      Top             =   1080
      Width           =   615
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Command1_Click(Index As Integer)
    Dim lBuf As String
    Dim lChar(1 To 4) As String
   
    lBuf = Trim$(Text1.Text)
    If lBuf = "" Then lBuf = " "
    With Command1(Index)
        Select Case Index
            Case 0, 9 To 11
                lChar(1) = Right$(.Caption, 1)
                lChar(2) = Right$(.Caption, 1)
                lChar(3) = Right$(.Caption, 1)
                lChar(4) = Right$(.Caption, 1)
            Case 1 To 8
                lChar(1) = Right$(.Caption, 1)
                lChar(2) = Mid$(.Caption, 1, 1)
                lChar(3) = Mid$(.Caption, 2, 1)
                lChar(4) = Mid$(.Caption, 3, 1)
        End Select
        Select Case Right$(lBuf, 1)
            Case lChar(1): Mid$(lBuf, Len(lBuf), 1) = lChar(2)
            Case lChar(2): Mid$(lBuf, Len(lBuf), 1) = lChar(3)
            Case lChar(3): Mid$(lBuf, Len(lBuf), 1) = lChar(4)
            Case lChar(4): Mid$(lBuf, Len(lBuf), 1) = lChar(1)
            Case Else
                lBuf = Trim$(lBuf) + lChar(1)
        End Select
    End With
    Text1.Text = lBuf
End Sub

Private Sub Form_Load()
Text1.Text = ""
Command1(0).Caption = vbCrLf + "1"
Command1(1).Caption = "ABC" + vbCrLf + "2"
Command1(2).Caption = "DEF" + vbCrLf + "3"
Command1(3).Caption = "GHI" + vbCrLf + "4"
Command1(4).Caption = "JKL" + vbCrLf + "5"
Command1(5).Caption = "MNO" + vbCrLf + "6"
Command1(6).Caption = "PRS" + vbCrLf + "7"
Command1(7).Caption = "TUV" + vbCrLf + "8"
Command1(8).Caption = "WXY" + vbCrLf + "9"
Command1(9).Caption = vbCrLf + "*"
Command1(10).Caption = vbCrLf + "0"
Command1(11).Caption = vbCrLf + "#"
End Sub


0
 
Erick37Commented:
Nice code mcrider!
But how do you enter "HELLO" or 5551212 ?
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
mcriderCommented:
Replace the Command1_Click subroutine with the following code... Then if you want to use the same key as one of the next characters, right-click to move to the next character.

For example, to spell hello:

   click "4" 3 times.
   click "3" 3 times.
   click "5" 4 times.
   right-click "5" once.
   click "5" 4 times.
   click "6" 4 times.  


Cheers!


THE CODE:

Private Sub Command1_Click(Index As Integer)
    Dim lBuf As String
    Dim lChar(1 To 4) As String
   
    lBuf = Trim$(Text1.Text)
    If lBuf = "" Then lBuf = " "
    With Command1(Index)
        Select Case Index
            Case 0, 9 To 11
                lChar(1) = Right$(.Caption, 1)
                lChar(2) = Right$(.Caption, 1)
                lChar(3) = Right$(.Caption, 1)
                lChar(4) = Right$(.Caption, 1)
            Case 1 To 8
                lChar(1) = Right$(.Caption, 1)
                lChar(2) = Mid$(.Caption, 1, 1)
                lChar(3) = Mid$(.Caption, 2, 1)
                lChar(4) = Mid$(.Caption, 3, 1)
        End Select
        Select Case Right$(lBuf, 1)
            Case lChar(1): Mid$(lBuf, Len(lBuf), 1) = lChar(2)
            Case lChar(2): Mid$(lBuf, Len(lBuf), 1) = lChar(3)
            Case lChar(3): Mid$(lBuf, Len(lBuf), 1) = lChar(4)
            Case lChar(4): Mid$(lBuf, Len(lBuf), 1) = lChar(1)
            Case "_": Mid$(lBuf, Len(lBuf), 1) = lChar(1)
            Case Else
                lBuf = Trim$(lBuf) + lChar(1)
        End Select
    End With
    Text1.Text = lBuf
End Sub
Private Sub Command1_MouseUp(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = 2 Then Text1.Text = Trim$(Text1.Text) + "_"
End Sub
0
 
mcriderCommented:
By the way, using the above code, you will get an "_" for every right-click...  So to spell "HELLO_MIKE", you can:

   click "4" 3 times.
   click "3" 3 times.
   click "5" 4 times.
   right-click "5" once.
   click "5" 4 times.
   click "6" 4 times.
   right-click "5" once.
   right-click "5" once.
   click "6" 2 times.
   click "4" 4 times.
   click "5" 3 times.
   click "3" 3 times.


Cheers!




0
 
mcriderCommented:
By the way, Q and Z don't exist on a phone keypad... If you want Q and Z support, let me know...


Cheers!
0

Featured Post

Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now