QUESTION: I need to modify VB program running on Visual Studio 2010 (that checks
ID: 3639010 • Letter: Q
Question
QUESTION:
I need to modify VB program running on Visual Studio 2010 (that checks value of words input by user and in dictionary text file) to a VB program that looks for words composed of the letters (any letters) of a word input by the user from a dictionary text file. Please include image of your program final output and your program.
BODY:
The original program is a Visual Basic 2010 program using Visual Studio 2010 that allows a user to input a word (and also searches for words in the dictionary, English language, etc… that equals exactly 100 based on the rule below), then the program calculates the value of the inputted word based on the rule below:
A=1 cent, B=2 cents, C=3 cents.....Z=26 cents.
I need to modify this program so instead of looking for words that equal 100 based on the rule, the program takes in input words from user and looks for words composed of the letters of the input word and test those words to a dictionary text file and displays all of the words made of the input word in a list box.
The VB program using Visual Studio 2010 should look for words composed of the letters (any letters) of a word input by the user. Please include image of your program final output and your program.The program should search for words in any given list of letters.
Example:
TELEPHONE = hope, help, hotel, then, hole, open, teen...etc.
I need to Input a Dictionary sequential Text file into the program and use the FileDialog Box to select the Dictionary File
The program should:
- Loop thru the dictionary looking for words that are in the given word/letters.
- Display a list of those words in a listbox.
Please include image of your program final output and code
Can download project at :
http://www.sharebees.com/dw0h412rdf3s.html
[Code]
Imports System.IO
Public Class Form1
Dim FilePath As String
Private _inStr As Integer
Private _mid As String
Private Property InStr(ByVal p1 As Integer, ByVal textBox As TextBox, ByVal p3 As String) As Integer
Get
Return _inStr
End Get
Set(ByVal value As Integer)
_inStr = value
End Set
End Property
Private Property Mid(ByVal textBox As TextBox, ByVal p2 As Integer, ByVal p3 As Integer) As String
Get
Return _mid
End Get
Set(ByVal value As String)
_mid = value
End Set
End Property
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub scrambleButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles scrambleButton.Click
Dim Counter As Integer
Dim StartPos As Integer
Dim NumOfWords As Integer
If Trim(TextBox1.Text) = "" Then
NumOfWords = 0
Exit Sub
End If
TextBox1 = Trim(TextBox1) ' Remove All Spaces
While InStr(1, TextBox1, " ") > 0 'Remove Double Spaces
StartPos = InStr(1, TextBox1, " ")
TextBox1 = Mid(TextBox1, 1, StartPos - 1) & _
Mid(TextBox1, StartPos + 1, Len(TextBox1) - StartPos)
End While
NumOfWords = 1
For Counter = 1 To Len(TextBox1)
If Mid(TextBox1, Counter, 1) = " " Then
NumOfWords = NumOfWords + 1
End If
Next Counter
MsgBox("Found " & NumOfWords & " Words")
End Sub
Private Sub clearButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
TextBox1.Text = ""
ListBox1.Items.Clear()
TextBox2.Text = ""
TextBox1.Focus()
End Sub
Private Sub calcButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles calcButton.Click
MsgBox(GetWordValue(TextBox1.Text)) 'shows messagebox
' ListBox1.Items.Add(TextBox1.Text)
If GetWordValue(TextBox1.Text) = 100 Then '
ListBox1.Items.Add(TextBox1.Text)
TextBox2.Text = "YES THIS WORD LETTERS CAN BE SCRAMBLE TO FORM OTHER WORDS" 'shows answer
Else
TextBox2.Text = "NO THIS WORD LETTERS CAN BE SCRAMBLE TO FORM OTHER WORDS" 'shows answer
End If
End Sub
Private Function GetFileDictionary() As String
Dim FileDialog As New OpenFileDialog()
FileDialog.FilterIndex = 1
If FileDialog.ShowDialog() = DialogResult.OK Then
GetFileDictionary = FileDialog.FileName
Else
GetFileDictionary = vbNullString
End If
End Function
Private Sub GetListInfo(ByVal FilePath As String)
Dim DictionaryReader As New StreamReader(FilePath)
Dim sLine As String = vbNullString
Dim wValue As Long = 0
Dim Wordscount As Long = 0
Dim Words100 As Long = 0
Dim maxValue As Long = 0
Dim maxWord As String = vbNullString
Dim MaxChars As Long = 0
Dim MaxWordChars As String = vbNullString
Dim MinChars As Long = Long.MaxValue
Dim MinWordChars As String = vbNullString
Dim average As Double = 0
Do
sLine = DictionaryReader.ReadLine()
If Not sLine Is Nothing Then
Wordscount = Wordscount + 1
wValue = GetWordValue(sLine)
If wValue = 100 Then
Words100 = Words100 + 1
ListBox1.Items.Add(sLine)
If sLine.Length > MaxChars Then
MaxChars = sLine.Length
MaxWordChars = sLine
End If
If sLine.Length < MinChars Then
MinChars = sLine.Length
MinWordChars = sLine
End If
End If
If wValue > maxValue Then
maxValue = wValue
maxWord = sLine
End If
End If
Loop Until sLine Is Nothing
'
average = Words100 / Wordscount
' .
MsgBox("number of words in the dictionary : " + Wordscount.ToString + vbNewLine +
"number of words compossed of the inputed word from the user are: " + Words100.ToString + vbNewLine +
"the word that is most popular : " + maxWord + " with value of " + maxValue.ToString + vbNewLine +
"the word compossed of the inputed word from the user with maximum number of chars: " + MaxWordChars + vbNewLine +
"the word equal 100compossed of the inputed word from the user with minimum number of chars: " + MinWordChars + vbNewLine +
"the average number of words compossed of the inputed word from the user: " + average.ToString)
End Sub
Private Function GetWordValue(ByVal str As String) As Long
'
Dim i As Long
Dim arr() As Char = str.ToUpper().ToCharArray()
Dim sum As Long
For i = 0 To str.Length - 1 Step 1
sum += AscW(arr(i)) - 64 ' this way to convert each character to integer number
Next i
GetWordValue = sum
End Function
Private Sub GetWordFromList(ByVal str As String)
On Error Resume Next
Dim size As Long = GetWordValue(str)
Dim found As Boolean = False
If ListBox1.Items.Count = 0 Then
'
MsgBox("there is no items in the list have the same value")
Exit Sub
End If
For i = 0 To ListBox1.Items.Count
If size = GetWordValue(ListBox1.Items.Item(i)) Then
MsgBox("the equivalent word in the list is: " & ListBox1.Items.Item(i))
Exit Sub
End If
Next
MsgBox("there is no items in the list have the same value")
End Sub
'
Private Sub exitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Me.Close()
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub TextBox2_TextChanged_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged
End Sub
Private Sub FilePath_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FilePth.Click
End Sub
Private Sub searchButton_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles searchButton.Click
GetWordFromList(TextBox1.Text)
End Sub
Private Sub accessButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles accessButton.Click
If FilePath <> vbNullString Then
GetListInfo(FilePath)
End If
End Sub
Private Sub assignButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles assignButton.Click
FilePath = GetFileDictionary()
TextBox2.Text = "Dictionary Path: " + FilePath
End Sub
Private Function Trim(ByVal textBox As TextBox) As TextBox
Throw New NotImplementedException
End Function
Private Function Trim(ByVal p1 As String) As String
Throw New NotImplementedException
End Function
End Class
[/Code]
Explanation / Answer
Public Class Form1 Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click MsgBox(GetWordValue(TextBox1.Text)) ListBox1.Items.Add(TextBox1.Text) If GetWordValue(TextBox1.Text) = 100 Then Label3.Text = "YES" Else Label3.Text = "NO" End If End Sub Private Function GetWordValue(str As String)As Long Dim i As Long Dim arr() As Char = str.ToUpper().ToCharArray() Dim sum As Long For i = 0 To str.Length - 1 Step 1 sum += AscW(arr(i)) - 64 ' this way to convert each character to integer number Next i GetWordValue = sum End Function Private Sub GetWordFromList(str As String) on Error Resume Next Dim size As Long = GetWordValue(str) Dim found As Boolean = False If ListBox1.Items.Count = 0 Then MsgBox("there is no items in the list have the same value") Exit Sub End If For i = 0 To ListBox1.Items.Count If size = GetWordValue(ListBox1.Items.Item(i)) Then MsgBox("the equivalent word in the list is: " & ListBox1.Items.Item(i)) Exit Sub End If Next MsgBox("there is no items in the list have the same value") End Sub Private Sub ListBox1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ListBox1.SelectedIndexChanged End Sub Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click me.Close End Sub Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click GetWordFromList(TextBox1.Text) End Sub Private Sub Button4_Click(sender As System.Object, e As System.EventArgs) Handles Button4.Click TextBox1.Text = "" ListBox1.Items.Clear() Label3.Text = "" TextBox1.Focus() End Sub End Class