alright so i have a problem iam working on i have to enter a 7 digit phonenumber then generate a word so example 639-2277 word mean the word newcars or any number would come up as a word well i cant get words to generate only random letters annd right now my code has an error with the txtphonenumber handle idk how to fix it so please help me here is the code :

Partial Class frmPhoneWordGen
Inherits System.Windows.Forms.Form
Public Numbers(7, 3) As String
Public Phonenumber As Integer
Public output As String
Private Sub frmPhoneWordGen_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Numbers(0, 0) = "A" 
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 btnGenerateWord_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGenerateWord.Click

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
Dim word As String = ""
'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

End Sub

Private Sub txtPhoneNumber_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PhoneNumberTextBox.TextChanged
Phonenumber = txtPhoneNumber.Text
End Sub
Private Function GetNumber() As String
Return txtPhoneNumber.Text()
End Function
End Class

please anyone out there iam still fairly newish to this all been reading three books and surfing and just testing testing editing still nada help me =]

5 Years
Discussion Span
Last Post by Reverend Jim

First of all, when you post code, please do it without the line numbers. It screws up the formatting. Now for the problem. I presume that the letters you use are restricted to those on a phone keypad corresponding to the digits in the phone number. If so, you really should have mentioned that instead of making me deduce that from the code. So you are supposed to generate words based on the digits with that restriction. How, exactly, are you going to determine whether the random strings you generate are actually words? Do you have a dictionary of words to check against?

To start with, I wouldn't store the digit to letter mappings the way you have set up. I would create a string array of 10 elements (indexed 0-9) where each element contains all of the letters that appear for that digit. That is coded as

Dim map() As String = {"", "", "ABC", "DEF", "GHI", "JKL", "MNO", "PQRS", "TUV", "WXYZ"}

That would indicate that any telephone numbers containing the digits 0 or 1 would be disqualified. In any case, I need more information about the problem before I can make further suggestions.

One further comment

my code has an error with the txtphonenumber handle idk

I don't know what you mean by "handle idk". Please try to avoid using abbreviations that are not obvious to others. I don't mind going to go to the trouble of composing a lengthy explanation so I would like you to go to the effort of composing a clear question.

Edited by Reverend Jim: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.