Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

how do I write the code for this I have half my code but it won\'t work properly

ID: 3601472 • Letter: H

Question

how do I write the code for this I have half my code but it won't work properly!.

Public Class Form1

'create a new empty dictionary where we'll add the pairs of english and
'textese words
Dim englishToTextese As New Dictionary(Of String, String)
Private ReadOnly word As Object
Private ReadOnly txtEngTotxtEse As Object

Private Function IsCaptialized(word As String)
'If the first character in the word is upper case then return true
'else return false

If Mid(word, 1, 1) = Mid(word, 1, 1).ToUpper Then

Return True
Else
Return False
End If

End Function
Private Function GetPunctuation(word As String) As Tuple(Of String, String)
'If the last character in the word is a punctuation mark, return a pair of values which are :
'the word without puctuation, and the punctuation. Else
'return the word and an empty string
Dim result As Tuple(Of String, String)
If "!':;?/.,".Contains(word.Last()) Then
result = New Tuple(Of String, String)(Mid(word, 1, word.Length - 1), word.Last)
Else
result = New Tuple(Of String, String)(word, "")
End If
Return result
End Function
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'Split each line into its elements and add to the dictionary
Dim filedata() As String = IO.File.ReadAllLines("C:/Users/Owner/Documents/Textese.txt")

For Each item As String In filedata
Dim splitstring() As String = item.Split(","c)
txtEngTotxtEse.Add(splitstring(0), splitstring(1))
Next
End Sub
Private Sub btnTranslate_Click(sender As Object, e As EventArgs) Handles btnTranslate.Click
'load textese dictionary to an array
Dim txtEse(word) As String
Dim englishWord As String
Dim IsCapitalized(englishWord) As String

Dim textese As String = ""
'split the text in the txtEnglish textbox into its component words including any punctuation
Dim words() As String = txtEng.Text.Split(" "c)
For Each txtEng As String In words
'get the word and any punctuation following it as a pair of items
'and store in punctResult
Dim punctResult As Tuple(Of String, String) = GetPunctuation(txtEng)
Dim texteseWord As String
'store the first item (the word) in englishWord
englishWord = punctResult.Item1
'store the secont item (the punctuation or a blank string) in punctuation
Dim punctuation As String = punctResult.Item2
'If the english word is in the dictionary
If englishToTextese.ContainsKey(englishWord.ToLower) Then
'get the textesevertion
texteseWord = englishToTextese(englishWord.ToLower)
'if the original english word was capiutalized, capitalize the textese word
If IsCapitalized(englishWord) Then
texteseWord = texteseWord.ToUpperInvariant
End If
'add the word to the textese sentence
textese = textese & texteseWord & punctuation & " "
Else
'if the word isn't in the dictionary, add the original english word and its original state
'of capitalization and punctuation to the textese sentence
textese = textese & englishWord & punctuation & " "
End If
Next
'store the new texteze sentence in the textbox
Me.txtEse.Text = textese


End Sub


End Class

Explanation / Answer

The problem is you haven't specified the return type of IsCaptialized function and also in Sub btnTranslate_Click, you are defining it as returning string i.e  Dim IsCapitalized(englishWord) As String . It should be changed to  Dim IsCapitalized(englishWord) As Boolean. So the code with changes is as follows :

Public Class Form1

'create a new empty dictionary where we'll add the pairs of english and

'textese words

Dim englishToTextese As New Dictionary(Of String, String)

Private ReadOnly word As Object

Private ReadOnly txtEngTotxtEse As Object

  

Private Function IsCaptialized(word As String) As Boolean

'If the first character in the word is upper case then return true

'else return false

If Mid(word, 1, 1) = Mid(word, 1, 1).ToUpper Then

Return True

Else

Return False

End If

End Function

  

Private Function GetPunctuation(word As String) As Tuple(Of String, String)

'If the last character in the word is a punctuation mark, return a pair of values which are :

'the word without puctuation, and the punctuation. Else

'return the word and an empty string

Dim result As Tuple(Of String, String)

If "!':;?/.,".Contains(word.Last()) Then

result = New Tuple(Of String, String)(Mid(word, 1, word.Length - 1), word.Last)

Else

result = New Tuple(Of String, String)(word, "")

End If

Return result

End Function

  

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

'Split each line into its elements and add to the dictionary

Dim filedata() As String = IO.File.ReadAllLines("C:/Users/Owner/Documents/Textese.txt")

For Each item As String In filedata

Dim splitstring() As String = item.Split(","c)

txtEngTotxtEse.Add(splitstring(0), splitstring(1))

Next

End Sub

  

Private Sub btnTranslate_Click(sender As Object, e As EventArgs) Handles btnTranslate.Click

'load textese dictionary to an array

Dim txtEse(word) As String

Dim englishWord As String

Dim IsCapitalized(englishWord) As Boolean

Dim textese As String = ""

'split the text in the txtEnglish textbox into its component words including any punctuation

Dim words() As String = txtEng.Text.Split(" "c)

For Each txtEng As String In words

'get the word and any punctuation following it as a pair of items

'and store in punctResult

Dim punctResult As Tuple(Of String, String) = GetPunctuation(txtEng)

Dim texteseWord As String

'store the first item (the word) in englishWord

englishWord = punctResult.Item1

'store the secont item (the punctuation or a blank string) in punctuation

Dim punctuation As String = punctResult.Item2

'If the english word is in the dictionary

If englishToTextese.ContainsKey(englishWord.ToLower) Then

'get the textesevertion

texteseWord = englishToTextese(englishWord.ToLower)

'if the original english word was capiutalized, capitalize the textese word

If IsCapitalized(englishWord) Then

texteseWord = texteseWord.ToUpperInvariant

End If

'add the word to the textese sentence

textese = textese & texteseWord & punctuation & " "

Else

'if the word isn't in the dictionary, add the original english word and its original state

'of capitalization and punctuation to the textese sentence

textese = textese & englishWord & punctuation & " "

End If

Next

'store the new texteze sentence in the textbox

Me.txtEse.Text = textese

End Sub

End Class