I am trying to create a telephone word generator that ask for seven digit number in a textbox and displays every possible seven letter word combination corresponding to that number when user clicks generate words button. My generate click button is not working once click

Public Numbers(7, 3) As String
    Public Phonenumber As Integer
    Public output As String

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
        ' Dim Numbers(7, 3) As String       
        Numbers(0, 0) = "A" '2        
        Numbers(0, 1) = "B" '2           
        Numbers(0, 2) = "C" '2            
        Numbers(1, 0) = "D" '3            
        Numbers(1, 1) = "E" '3            
        Numbers(1, 2) = "F" '3           
        Numbers(2, 0) = "G" '4           
        Numbers(2, 1) = "H" '4           
        Numbers(2, 2) = "I" '4           
        Numbers(3, 0) = "J" '5           
        Numbers(3, 1) = "K" '5        
        Numbers(3, 2) = "L" '5          
        Numbers(4, 0) = "M" '6          
        Numbers(4, 1) = "N" '6          
        Numbers(4, 2) = "O" '6          
        Numbers(5, 0) = "P" '7           
        Numbers(5, 1) = "R" '7           
        Numbers(5, 2) = "S" '7           
        Numbers(6, 0) = "T" '8            
        Numbers(6, 1) = "U" '8           
        Numbers(6, 2) = "V" '8           
        Numbers(7, 0) = "W" '9           
        Numbers(7, 1) = "X" '9           
        Numbers(7, 2) = "Y" '9      
    End Sub

    Private Sub GenerateButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

        Dim phoneNumber As String = GetNumber()

        'check if the number contains 0 or 1
        While phoneNumber.Contains("0") Or phoneNumber.Contains("1")
            phoneNumber = GetNumber()
        End While

        'create a hashtable to hold the digits
        Dim arrayL As New Hashtable
        Dim x As Integer = 1
        For i As Integer = 65 To 90 Step 3
            arrayL.Add(x, New Char() {Chr(i), Chr(i + 1), Chr(i + 2)})
            x += 1
        Next

        Dim word As String = ""
        Dim counter As Integer
        'creates only 3 words out of the phonenumber
        For i As Integer = 0 To 2

            For Each s As String In phoneNumber
                word = word & DirectCast(arrayL.Item(CInt(s)), Char())(i).ToString

            Next
            output = (counter & "" & vbNewLine)
        Next

    End Sub

    Private Sub PhoneNumberTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Phonenumber = Phonenumber

    End Sub
    Private Function GetNumber() As String

        Return Phonenumber
    End Function


End Module

You do, of course, realize that at 7 digits and allowing 3 possible characters per digit, you're going to generate 2187 different "words." If you allow for 4 characters for 7 (pqrs) and 9 (wxyz), then you can get 3888 words.

Here's something I quickly put together, and I'm even allowing 0 or 1 to be used (will be a space). I'm sure it's not the best approach, because it's not scalable without modification since it is programmed specifically for a 7 digit input, but hey. It's a start.

Sub Main()

        Dim dictionary As New Dictionary(Of Integer, String)

        dictionary.Add(1, " ")
        dictionary.Add(2, "ABC")
        dictionary.Add(3, "DEF")
        dictionary.Add(4, "GHI")
        dictionary.Add(5, "JKL")
        dictionary.Add(6, "MNO")
        dictionary.Add(7, "PQRS")
        dictionary.Add(8, "TUV")
        dictionary.Add(9, "WXYZ")
        dictionary.Add(0, " ")

        ' array representing a possible user input
        Dim inputs As Integer() = {8, 6, 7, 5, 3, 0, 9}

        Dim query = (From input In inputs _
                    From c In dictionary.Where(Function(pair) pair.Key = input).Select(Function(pair) pair.Value.ToCharArray()) _
                    Select c).ToArray()

        Dim words = From item0 In query(0) _
                    From item1 In query(1) _
                    From item2 In query(2) _
                    From item3 In query(3) _
                    From item4 In query(4) _
                    From item5 In query(5) _
                    From item6 In query(6) _
                    Select New Char() {item0, item1, item2, item3, item4, item5, item6}

        For Each word In words

            Console.WriteLine(New String(word))

        Next

        Console.Read()

    End Sub

It uses LINQ and since I tie multiple "from" statements together without specifying a join, it in effect creates a full cartesian join on the data sets, basically matching everything to everything else and thus generating all possible "words" for the given input. Since I'm allowing spaces, my particular input will get 1296 combinations.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.