I have a program in which a user enters a sentence in English into a text box, then the sentence is translated into French and German based on words in an array of structures that gets its values from a text file. I have almost all of the program written, but I am a bit confused on how to get VB to get the English words that are entered into the text box separately so they can be translated individually and the value returned. I need help with this last part. I need to use a Sub Procedure to get the English Words and to Translate them. Any help would be appreciated.

Here is what I have so far.

Public Class frmTranslate
    
    ' Create Structure with a member for each language
    Structure Translator
        Dim english As String
        Dim french As String
        Dim german As String
    End Structure

    ' Create array of structures
    Dim trans(15) As Translator

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

        'Add words to array of structures trans().
        Dim temp As Translator
        Dim sr As IO.StreamReader = IO.File.OpenText("words.TXT")
        For i As Integer = 0 To 15
            trans(i).english = sr.ReadLine
            trans(i).french = sr.ReadLine
            trans(i).german = sr.ReadLine
        Next

        'Close the reader
        sr.Close()

        'Perform bubble sort by English word.
        For i As Integer = 1 To 15
            For j As Integer = 1 To 16 - i
                If Trans(j - 1).english > Trans(j).english Then
                    temp = Trans(j - 1)
                    Trans(j - 1) = Trans(j)
                    Trans(j) = temp
                End If
            Next
        Next
    End Sub

    Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblFrench.Click

    End Sub

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

        'Translate English sentence to French and German.
        Dim english() As String

        'Hold results
        Dim sentence As Translator

        'Ensure the sentence ends with a period, get English words
        Dim line As String = tbxEnterSentence.Text.Trim.ToUpper
        If line.Substring(line.Length - 1) <> "." Then
            line &= "."
        End If
        english = GetWords(line)
        sentence = Translate(english)

        'Display the results, format sentence to have period at the end
        tbxFrench.Text = sentence.french.Trim & "."
        tbxGerman.Text = sentence.german.Trim & "."

    End Sub

    Sub GetWords(ByVal line As String)

    End Sub

    End Sub

    Sub Translate(ByVal english As String)




    End Sub

End Class

Try this out...

Function GetWords(ByVal line As String) As String()
        Return line.Replace(".", "").Split(" ")
    End Function

Removes the period too. Maybe you'll want to remove other punctuation too.

Try this out...

Function GetWords(ByVal line As String) As String()
        Return line.Replace(".", "").Split(" ")
    End Function

Removes the period too. Maybe you'll want to remove other punctuation too.

thanks. I actually figured this part out, I am mainly having trouble with the final part

#
english = GetWords(line)
sentence = Translate(english)

'Display the results, format sentence to have period at the end
tbxFrench.Text = sentence.french.Trim & "."
tbxGerman.Text = sentence.german.Trim & "."

especially how to make the Translate(english) function actually translate all the words in the english sentence entered into french and german. I am not so good with arrays of structures, and Im really confused about this part.

How would the form look for a program that would translate phrases from english to french and german?

That is an awesome guideline on a translation program which would be very helpful for the programming. There are also various translation program from French to English in which words are based in an array of structures.

This article has been dead for over six months. Start a new discussion instead.