I am trying to make telephone number word generator, user enters phone number 7 digits between 2 to 9 and then it generates all possible word combinations,
it should be 3 ^ 7 = 2187

This is what I got so far:

Private Sub GenerateButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GenerateButton.Click
Dim i As String = PhoneNumberTextBox.Text

Dim one As Integer = i.Substring(0, 1) 'Remove each digit
Dim two As Integer = i.Substring(1, 1)
Dim three As Integer = i.Substring(2, 1)
Dim four As Integer = i.Substring(3, 1)
Dim five As Integer = i.Substring(4, 1)
Dim six As Integer = i.Substring(5, 1)
Dim seven As Integer = i.Substring(6, 1)

calculate(one)
calculate(two)

End Sub

Function calculate(ByVal number As Integer)

If number = 1 Or 0 Then
MessageBox.Show(" Please input numbers between 2 to 9 ")

ElseIf number = 2 Then
For r As Integer = 0 To array1.GetUpperBound(0)
array1 = {{"A", "B", "C"}}
For i As Integer = 0 To array1.GetUpperBound(1)

' PhoneNumberWordsListBox.Items.Add(array1(0, i))
For number1 As Integer = 0 To array1.GetUpperBound(0)

' PhoneNumberWordsListBox.Items.Add(array1(0, i))
' TextBox1.AppendText(vbCrLf & array1(0, i))
Next
Next

Next

Return number

End Function

I know it is a mess I cannot figure out how to remove those substrings and to place in this array and then print :

Dim array1(,) As String = {{"A", " B", " C"}, {"D", " E", " F"}, _
{"G", " H", " I"}, {"J", " K", " L"}, {"M", " N", " O"}, _
{"P", " R", " S"}, {"T", " U", " V"}, {"W", " X", " Y"}}

Some hints would be great...

Thank you!

This is a problem that can be solved using recursivity.
This can be an example on how to:

Dim NumberToLetter As Char(,) = {{"A"c, "B"c, "C"c}, {"D"c, "E"c, "F"c}, _
	  {"G"c, "H"c, "I"c}, {"J"c, "K"c, "L"c}, {"M"c, "N"c, "O"c}, _
	  {"P"c, "R"c, "S"c}, {"T"c, "U"c, "V"c}, {"W"c, "X"c, "Y"c}}

	Function PhoneWordsGenerator(ByVal PhoneNumber As String) As String()
		'
		'	Declare the words to return
		'
		Dim Words As String()
		'
		'	Declare the initial character of the phone string to process
		'
		Dim Level As Integer = 0
		'
		'	Call to generate the words corresponding to the current level
		'
		Words = GenerateLevel(PhoneNumber, Level)
		'
		'	Sort the result
		'
		Array.Sort(Words)
		'
		'	Return them
		'
		Return Words
	End Function

	Function GenerateLevel(ByVal PhoneNumber As String, ByVal Level As Integer) As String()
		'
		'	Declare the words to return
		'
		Dim Words As String() = Nothing
		'
		'	If this is not the las character in the pnone string
		'
		If Level < PhoneNumber.Length - 1 Then
			'
			'	Get the sub words from the next character in the phone string
			'
			Dim SubWords As String()
			'
			'	Recursive call for the next level
			'
			SubWords = GenerateLevel(PhoneNumber, Level + 1)
			'
			'	Redim the words to return to hol 3 times the subwords returnes
			'
			ReDim Preserve Words((SubWords.Length * 3) - 1)
			'
			'	Declare the pointer to the insert word position in the words array
			'
			Dim WordPosition As Integer = 0
			'
			'  For each letter of the current level 
			'
			For I As Integer = 0 To 2
				'
				'	For each subword returned
				'
				For J As Integer = 0 To SubWords.Length - 1
					'
					'	Create a word adding to the current letter the sub words
					'
					Words(WordPosition) = NumberToLetter(Val(PhoneNumber.Chars(Level)) - 2, I).ToString & SubWords(J)
					'
					'	Advance one position
					'
					WordPosition += 1
				Next
			Next
		Else
			'
			'	This is the last character
			'	For the tree letters of the last number
			'
			ReDim Words(2)
			For I As Integer = 0 To 2
				'
				'	Add each letter 
				'
				Words(I) = NumberToLetter(Val(PhoneNumber.Chars(Level)) - 2, I).ToString
			Next
		End If
		Return Words
	End Function

The usage of all this stuff can be

Dim ResultingWords As String() = PhoneWordsGenerator("6835483")

Hope this helps

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

Hey if it works for you, past the code , i wanna try too make it too im just learning

Hey if it works for you, past the code , i wanna try too make it too im just learning

I got it work little differently :

Dim letters(,) As String = {{" ", " ", " "},
{" ", " ", " "}, {"A", "B", "C"}, {"D", "E", "F"},
{"G", "H", "I"}, {"J", "K", "L"}, {"M", "N", "O"},
{"P", "R", "S"}, {"T", "U", "V"}, {"W", "X", "Y"}}
 
 
 
 
 
 
 
For loop1 = 0 To 2
For loop2 = 0 To 2
For loop3 = 0 To 2
For loop4 = 0 To 2
For loop5 = 0 To 2
  For loop6 = 0 To 2
    For loop7 = 0 To 2
output &= String.Format(
    letters(digits(0), loop1) &
    letters(digits(1), loop2) &
    letters(digits(2), loop3) &
    letters(digits(3), loop4) &
    letters(digits(4), loop5) &
    letters(digits(5), loop6) &
    letters(digits(6), loop7))
Next loop7
Next loop6
Next loop5
Next loop4
Next loop3
Next loop2
Next loop1

oh cool

Hey u got the whole code post it if u do plz

But how to do the same in the Visual Basic for Applications?
Please help me I need it for school

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.