0 Replies - 1272 Views - Last Post: 12 December 2007 - 11:55 AM Rate Topic: -----

#1 WizX   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 14-October 07

Reading letters in input and displaying them in listbox

Posted 12 December 2007 - 11:55 AM

Hi all,

I'm trying to finish up my semester project and have ran into a problem.

Basically, the program is supposed to take the letters I put input in the textbox, such as "AABBCEG" and return words such as "CABBAGE" "CAGE" BAG" etc, but instead it's returning words that contain ALL of the letters, so I'm getting results like "BACKGROUNDER" "CARPETBAG" "CELEBRATING", etc. I was wondering if someone gets a free moment if you could help me come up with the correct code that I'm looking for? I'm thinking it should only be a few lines that I'm missing that will fix it. Here is my code:

 Public Class Form1

	Private Sub btnGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGo.Click
		lstWords.Items.Clear()
		Dim allwords As IO.StreamReader = New IO.StreamReader("c:\dictionary.txt")

		Dim strInput As String = txtInput.Text  'The input
		Dim inputChar As Char() = strInput.ToUpper.ToCharArray 'This is the character array that would contain all of the characters (letters) in the input string in a list
		'This is used to test and see if the character is there
		Do While allwords.Peek <> -1
			Dim testcount As Integer = 0
			Dim file As String = allwords.ReadLine
			For Each c As Char In inputChar ' Loop that runs through and looks at each character in the array
				If file.Contains(c.ToString) Then
					testcount += 1 ' If the word you're currently looking at contains that character, increment the counter by one
				End If
			Next

			If testcount = inputChar.Length Then ' This is where the testcount comes in.  Essentially this takes the number and if all the characters in the array (the input string) were found in the word, then it outputs the word
				lstWords.Items.Add(file)
			End If
		Loop
	End Sub
End Class 


Thanks for any help.

Is This A Good Question/Topic? 0
  • +

Page 1 of 1