Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 149,938 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,424 people online right now. Registration is fast and FREE... Join Now!




Reading letters in input and displaying them in listbox

 
Reply to this topicStart new topic

Reading letters in input and displaying them in listbox

WizX
12 Dec, 2007 - 10:55 AM
Post #1

New D.I.C Head
*

Joined: 13 Oct, 2007
Posts: 9


My Contributions
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:

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.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 04:32PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month