hi, i'm starting to learn vb.net, and i trying to make some special translating program, its need to translate hebrew text into special letter sequence.

for example:

the text input are: בניית ביניינים מתקדמים (which its means Construction of advanced buildings )

And the text output are: BPJJZ_BJPJJPJM_NZWDNJM according to the list i made (Attached picture).


and i made this code:

Public Class MainForm

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If TextBox1.Text.Contains("א") Then TextBox2.Text = TextBox2.Text & "A"
        If TextBox1.Text.Contains("ב") Then TextBox2.Text = TextBox2.Text & "B"
        If TextBox1.Text.Contains("ג") Then TextBox2.Text = TextBox2.Text & "C"
        If TextBox1.Text.Contains("ד") Then TextBox2.Text = TextBox2.Text & "D"
        If TextBox1.Text.Contains("ה") Then TextBox2.Text = TextBox2.Text & "E"
        If TextBox1.Text.Contains("ו") Then TextBox2.Text = TextBox2.Text & "F"
        If TextBox1.Text.Contains("ז") Then TextBox2.Text = TextBox2.Text & "G"
        If TextBox1.Text.Contains("ח") Then TextBox2.Text = TextBox2.Text & "H"
        If TextBox1.Text.Contains("ט") Then TextBox2.Text = TextBox2.Text & "I"
        If TextBox1.Text.Contains("י") Then TextBox2.Text = TextBox2.Text & "J"
        If TextBox1.Text.Contains("כ") Then TextBox2.Text = TextBox2.Text & "K"
        If TextBox1.Text.Contains("ל") Then TextBox2.Text = TextBox2.Text & "L"
        If TextBox1.Text.Contains("ם") Then TextBox2.Text = TextBox2.Text & "M"
        If TextBox1.Text.Contains("מ") Then TextBox2.Text = TextBox2.Text & "N"
        If TextBox1.Text.Contains("ן") Then TextBox2.Text = TextBox2.Text & "O"
        If TextBox1.Text.Contains("נ") Then TextBox2.Text = TextBox2.Text & "P"
        If TextBox1.Text.Contains("ס") Then TextBox2.Text = TextBox2.Text & "Q"
        If TextBox1.Text.Contains("ע") Then TextBox2.Text = TextBox2.Text & "R"
        If TextBox1.Text.Contains("ף") Then TextBox2.Text = TextBox2.Text & "S"
        If TextBox1.Text.Contains("פ") Then TextBox2.Text = TextBox2.Text & "T"
        If TextBox1.Text.Contains("ץ") Then TextBox2.Text = TextBox2.Text & "U"
        If TextBox1.Text.Contains("צ") Then TextBox2.Text = TextBox2.Text & "V"
        If TextBox1.Text.Contains("ק") Then TextBox2.Text = TextBox2.Text & "W"
        If TextBox1.Text.Contains("ר") Then TextBox2.Text = TextBox2.Text & "X"
        If TextBox1.Text.Contains("ש") Then TextBox2.Text = TextBox2.Text & "Y"
        If TextBox1.Text.Contains("ת") Then TextBox2.Text = TextBox2.Text & "Z"
        If TextBox1.Text.Contains(" ") Then TextBox2.Text = TextBox2.Text & "_"
        If TextBox1.Text.Contains("?") Then TextBox2.Text = TextBox2.Text & "?"
        If TextBox1.Text.Contains("!") Then TextBox2.Text = TextBox2.Text & "!"
    End Sub
End Class

but there is a problem, its translate only one letter, for example:
im translating this sentence: בניית ביניינים מתקדמים (which its means Construction of advanced buildings )

and i get this word: BDJMNPWZ_ when the text output are should be like this: BPJJZ_BJPJJPJM_NZWDNJM can somebody help me with this problem?

thx, man1919.

The following code converts "בניית ביניינים מתקדמים" to "BPJJZ_BJPJJPJM_NZWDNJM"

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click

		TextBox2.Clear

		Dim dic As New Dictionary(Of Char, Char)
		With dic
			.Add("א"c, "A"c)
			.Add("ב"c, "B"c)
			.Add("ג"c, "C"c)
			.Add("ד"c, "D"c)
			.Add("ה"c, "E"c)
			.Add("ו"c, "F"c)
			.Add("ז"c, "G"c)
			.Add("ח"c, "H"c)
			.Add("ט"c, "I"c)
			.Add("י"c, "J"c)
			.Add("כ"c, "K"c)
			.Add("ל"c, "L"c)
			.Add("ם"c, "M"c)
			.Add("מ"c, "N"c)
			.Add("ן"c, "O"c)
			.Add("נ"c, "P"c)
			.Add("ס"c, "Q"c)
			.Add("ע"c, "R"c)
			.Add("ף"c, "S"c)
			.Add("פ"c, "T"c)
			.Add("ץ"c, "U"c)
			.Add("צ"c, "V"c)
			.Add("ק"c, "W"c)
			.Add("ר"c, "X"c)
			.Add("ש"c, "Y"c)
			.Add("ת"c, "Z"c)
			.Add(" "c, "_"c)
			.Add("?"c, "?"c)
			.Add("!"c, "!"c)
		End With

		For Each c As Char In TextBox1.Text
			TextBox2.AppendText(dic(c))
		Next

	End Sub

Its working!
Thank you very much! :)

PS: i made also untranslate button, so now the code looks like this:

Public Class MainForm

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        TextBox2.Clear()

        Dim dic As New Dictionary(Of Char, Char)
        With dic
            .Add("א"c, "A"c)
            .Add("ב"c, "B"c)
            .Add("ג"c, "C"c)
            .Add("ד"c, "D"c)
            .Add("ה"c, "E"c)
            .Add("ו"c, "F"c)
            .Add("ז"c, "G"c)
            .Add("ח"c, "H"c)
            .Add("ט"c, "I"c)
            .Add("י"c, "J"c)
            .Add("כ"c, "K"c)
            .Add("ל"c, "L"c)
            .Add("ם"c, "M"c)
            .Add("מ"c, "N"c)
            .Add("ן"c, "O"c)
            .Add("נ"c, "P"c)
            .Add("ס"c, "Q"c)
            .Add("ע"c, "R"c)
            .Add("ף"c, "S"c)
            .Add("פ"c, "T"c)
            .Add("ץ"c, "U"c)
            .Add("צ"c, "V"c)
            .Add("ק"c, "W"c)
            .Add("ר"c, "X"c)
            .Add("ש"c, "Y"c)
            .Add("ת"c, "Z"c)
            .Add(" "c, "_"c)
            .Add("?"c, "?"c)
            .Add("!"c, "!"c)
        End With

        For Each c As Char In TextBox1.Text
            TextBox2.AppendText(dic(c))
        Next

    End Sub


    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        About.Show()
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Close()
    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        TextBox1.Clear()
    End Sub

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged

    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        TextBox2.Clear()
    End Sub

    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
        If Clipboard.ContainsText = False Then MessageBox.Show("Paste failed, please try to copy again...", "Error")
        If Not Clipboard.ContainsText = False Then TextBox1.Text = Clipboard.GetText
    End Sub

    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        Clipboard.Clear()
        If Not TextBox2.Text = "" Then Clipboard.SetText(TextBox2.Text)
        If TextBox2.Text = "" Then MessageBox.Show("Copy failed, there are no any text...", "Error")
    End Sub

    Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click

        TextBox1.Clear()

        Dim dic As New Dictionary(Of Char, Char)
        With dic
            .Add("A"c, "א"c)
            .Add("B"c, "ב"c)
            .Add("C"c, "ג"c)
            .Add("D"c, "ד"c)
            .Add("E"c, "ה"c)
            .Add("F"c, "ו"c)
            .Add("G"c, "ז"c)
            .Add("H"c, "ח"c)
            .Add("I"c, "ט"c)
            .Add("J"c, "י"c)
            .Add("K"c, "כ"c)
            .Add("L"c, "ל"c)
            .Add("M"c, "ם"c)
            .Add("N"c, "מ"c)
            .Add("O"c, "ן"c)
            .Add("P"c, "נ"c)
            .Add("Q"c, "ס"c)
            .Add("R"c, "ע"c)
            .Add("S"c, "ף"c)
            .Add("T"c, "פ"c)
            .Add("U"c, "ץ"c)
            .Add("V"c, "צ"c)
            .Add("W"c, "ק"c)
            .Add("X"c, "ר"c)
            .Add("Y"c, "ש"c)
            .Add("Z"c, "ת"c)
            .Add("_"c, " "c)
            .Add("?"c, "?"c)
            .Add("!"c, "!"c)
        End With

        For Each c As Char In TextBox2.Text
            TextBox1.AppendText(dic(c))
        Next

    End Sub
End Class

but i want to add an error message and stop the action, when someone insert the text output into the text input, or insert letters in english into the text input. so its will not crush when someone do this.

i also attached picture of the error that i get.

thx, man1919.

hey i m now goin to learn abt ASP.NET can u tell me that IS It very Hard as compare to ADO.NET?
plz do rply fast

hey i m now goin to learn abt ASP.NET can u tell me that IS It very Hard as compare to ADO.NET?
plz do rply fast

sorry, i don't know the answer...(it's also not related to the topic...)
please start new thread with your question...

PS: i made also untranslate button, so now the code looks like this:

Public Class MainForm

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        TextBox2.Clear()

        Dim dic As New Dictionary(Of Char, Char)
        With dic
            .Add("א"c, "A"c)
            .Add("ב"c, "B"c)
            .Add("ג"c, "C"c)
            .Add("ד"c, "D"c)
            .Add("ה"c, "E"c)
            .Add("ו"c, "F"c)
            .Add("ז"c, "G"c)
            .Add("ח"c, "H"c)
            .Add("ט"c, "I"c)
            .Add("י"c, "J"c)
            .Add("כ"c, "K"c)
            .Add("ל"c, "L"c)
            .Add("ם"c, "M"c)
            .Add("מ"c, "N"c)
            .Add("ן"c, "O"c)
            .Add("נ"c, "P"c)
            .Add("ס"c, "Q"c)
            .Add("ע"c, "R"c)
            .Add("ף"c, "S"c)
            .Add("פ"c, "T"c)
            .Add("ץ"c, "U"c)
            .Add("צ"c, "V"c)
            .Add("ק"c, "W"c)
            .Add("ר"c, "X"c)
            .Add("ש"c, "Y"c)
            .Add("ת"c, "Z"c)
            .Add(" "c, "_"c)
            .Add("?"c, "?"c)
            .Add("!"c, "!"c)
        End With

        For Each c As Char In TextBox1.Text
            TextBox2.AppendText(dic(c))
        Next

    End Sub


    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        About.Show()
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Close()
    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        TextBox1.Clear()
    End Sub

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged

    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        TextBox2.Clear()
    End Sub

    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
        If Clipboard.ContainsText = False Then MessageBox.Show("Paste failed, please try to copy again...", "Error")
        If Not Clipboard.ContainsText = False Then TextBox1.Text = Clipboard.GetText
    End Sub

    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        Clipboard.Clear()
        If Not TextBox2.Text = "" Then Clipboard.SetText(TextBox2.Text)
        If TextBox2.Text = "" Then MessageBox.Show("Copy failed, there are no any text...", "Error")
    End Sub

    Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click

        TextBox1.Clear()

        Dim dic As New Dictionary(Of Char, Char)
        With dic
            .Add("A"c, "א"c)
            .Add("B"c, "ב"c)
            .Add("C"c, "ג"c)
            .Add("D"c, "ד"c)
            .Add("E"c, "ה"c)
            .Add("F"c, "ו"c)
            .Add("G"c, "ז"c)
            .Add("H"c, "ח"c)
            .Add("I"c, "ט"c)
            .Add("J"c, "י"c)
            .Add("K"c, "כ"c)
            .Add("L"c, "ל"c)
            .Add("M"c, "ם"c)
            .Add("N"c, "מ"c)
            .Add("O"c, "ן"c)
            .Add("P"c, "נ"c)
            .Add("Q"c, "ס"c)
            .Add("R"c, "ע"c)
            .Add("S"c, "ף"c)
            .Add("T"c, "פ"c)
            .Add("U"c, "ץ"c)
            .Add("V"c, "צ"c)
            .Add("W"c, "ק"c)
            .Add("X"c, "ר"c)
            .Add("Y"c, "ש"c)
            .Add("Z"c, "ת"c)
            .Add("_"c, " "c)
            .Add("?"c, "?"c)
            .Add("!"c, "!"c)
        End With

        For Each c As Char In TextBox2.Text
            TextBox1.AppendText(dic(c))
        Next

    End Sub
End Class

but i want to add an error message and stop the action, when someone insert the text output into the text input, or insert letters in english into the text input. so its will not crush when someone do this.

i also attached picture of the error that i get.

thx, man1919.

i attached now the picture of the error screen that i got, when i (by mistake) insert english letters in the text input.

Edit: if i press on the Enter key (to start a new line in the MultiLine textbox (text input box)) it's also crash and its show this message (in the attached picture).

can you help me solve this problem?

thx, man1919.

You are seeing this because you are not doing any error control.

Use a Try - Catch to handle the error:

Try TextBox1.AppendText(dic(c))
catch e as exception 
if e.message = "" then 'Insert the exact message of exception inside the double quotes.
Msgbox ("Invalid Input") 
else msgbox(e.message) 
end if  
end try

PS: This will only handle the error. If you want to avoid getting the error in the first place, append all characters in the dictionary (use the same char for both columns).

commented: Thank you, i didn't notice it before +1
Private Function GetDic() As Dictionary(Of Char, Char)
		Dim dic As New Dictionary(Of Char, Char)
		With dic
			.Add("א"c, "A"c)
			.Add("ב"c, "B"c)
			.Add("ג"c, "C"c)
			.Add("ד"c, "D"c)
			.Add("ה"c, "E"c)
			.Add("ו"c, "F"c)
			.Add("ז"c, "G"c)
			.Add("ח"c, "H"c)
			.Add("ט"c, "I"c)
			.Add("י"c, "J"c)
			.Add("כ"c, "K"c)
			.Add("ל"c, "L"c)
			.Add("ם"c, "M"c)
			.Add("מ"c, "N"c)
			.Add("ן"c, "O"c)
			.Add("נ"c, "P"c)
			.Add("ס"c, "Q"c)
			.Add("ע"c, "R"c)
			.Add("ף"c, "S"c)
			.Add("פ"c, "T"c)
			.Add("ץ"c, "U"c)
			.Add("צ"c, "V"c)
			.Add("ק"c, "W"c)
			.Add("ר"c, "X"c)
			.Add("ש"c, "Y"c)
			.Add("ת"c, "Z"c)
			.Add(" "c, "_"c)
			.Add("?"c, "?"c)
			.Add("!"c, "!"c)
		End With
		Return dic
	End Function

	Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click

		TextBox2.Clear()

		Dim dic As Dictionary(Of Char, Char) = GetDic()
		Try
			For Each c As Char In TextBox1.Text
				TextBox2.AppendText(If(dic.ContainsKey(c), dic(c), c)) 'if char is not in dictionary append the original (such as newLine)
			Next
		Catch ex As Exception
			MsgBox(String.Format("Error occured:{0}{1}", vbNewLine, ex.Message))
		End Try

	End Sub

	Private Sub Button8_Click(sender As System.Object, e As System.EventArgs) Handles Button8.Click
		
TextBox1.Clear()

		Dim dic As Dictionary(Of Char, Char) = GetDic()

		Try

			For Each c As Char In TextBox2.Text
				If dic.ContainsValue(c) Then
					Dim curChar As Char = c	'declare variable to stop LINQ's whine
					TextBox1.AppendText(dic.Where(Function(s) s.Value = curChar).First.Key)
				Else
					TextBox1.AppendText(c)
				End If
			Next
		Catch ex As Exception
			MsgBox(String.Format("Error occured:{0}{1}", vbNewLine, ex.Message))
		End Try
	End Sub
Private Function GetDic() As Dictionary(Of Char, Char)
		Dim dic As New Dictionary(Of Char, Char)
		With dic
			.Add("א"c, "A"c)
			.Add("ב"c, "B"c)
			.Add("ג"c, "C"c)
			.Add("ד"c, "D"c)
			.Add("ה"c, "E"c)
			.Add("ו"c, "F"c)
			.Add("ז"c, "G"c)
			.Add("ח"c, "H"c)
			.Add("ט"c, "I"c)
			.Add("י"c, "J"c)
			.Add("כ"c, "K"c)
			.Add("ל"c, "L"c)
			.Add("ם"c, "M"c)
			.Add("מ"c, "N"c)
			.Add("ן"c, "O"c)
			.Add("נ"c, "P"c)
			.Add("ס"c, "Q"c)
			.Add("ע"c, "R"c)
			.Add("ף"c, "S"c)
			.Add("פ"c, "T"c)
			.Add("ץ"c, "U"c)
			.Add("צ"c, "V"c)
			.Add("ק"c, "W"c)
			.Add("ר"c, "X"c)
			.Add("ש"c, "Y"c)
			.Add("ת"c, "Z"c)
			.Add(" "c, "_"c)
			.Add("?"c, "?"c)
			.Add("!"c, "!"c)
		End With
		Return dic
	End Function

	Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click

		TextBox2.Clear()

		Dim dic As Dictionary(Of Char, Char) = GetDic()
		Try
			For Each c As Char In TextBox1.Text
				TextBox2.AppendText(If(dic.ContainsKey(c), dic(c), c)) 'if char is not in dictionary append the original (such as newLine)
			Next
		Catch ex As Exception
			MsgBox(String.Format("Error occured:{0}{1}", vbNewLine, ex.Message))
		End Try

	End Sub

	Private Sub Button8_Click(sender As System.Object, e As System.EventArgs) Handles Button8.Click
		
TextBox1.Clear()

		Dim dic As Dictionary(Of Char, Char) = GetDic()

		Try

			For Each c As Char In TextBox2.Text
				If dic.ContainsValue(c) Then
					Dim curChar As Char = c	'declare variable to stop LINQ's whine
					TextBox1.AppendText(dic.Where(Function(s) s.Value = curChar).First.Key)
				Else
					TextBox1.AppendText(c)
				End If
			Next
		Catch ex As Exception
			MsgBox(String.Format("Error occured:{0}{1}", vbNewLine, ex.Message))
		End Try
	End Sub

Ok, I test it in debugging mode and it's fully working, But when i try to make an error (for teset it) I didn't got the error message, Maybe it's need to be MessageBox.Show instead ?

I even add an small chars option, With If Not event, Here is the full code:

Public Class MainForm
    Private Function GetDic() As Dictionary(Of Char, Char)
        Dim dic As New Dictionary(Of Char, Char)
        With dic
            If Not CheckBox1.Checked = True Then
                .Add("א"c, "A"c)
                .Add("ב"c, "B"c)
                .Add("ג"c, "C"c)
                .Add("ד"c, "D"c)
                .Add("ה"c, "E"c)
                .Add("ו"c, "F"c)
                .Add("ז"c, "G"c)
                .Add("ח"c, "H"c)
                .Add("ט"c, "I"c)
                .Add("י"c, "J"c)
                .Add("ך"c, "^"c)
                .Add("כ"c, "K"c)
                .Add("ל"c, "L"c)
                .Add("ם"c, "M"c)
                .Add("מ"c, "N"c)
                .Add("ן"c, "O"c)
                .Add("נ"c, "P"c)
                .Add("ס"c, "Q"c)
                .Add("ע"c, "R"c)
                .Add("ף"c, "S"c)
                .Add("פ"c, "T"c)
                .Add("ץ"c, "U"c)
                .Add("צ"c, "V"c)
                .Add("ק"c, "W"c)
                .Add("ר"c, "X"c)
                .Add("ש"c, "Y"c)
                .Add("ת"c, "Z"c)
                .Add(" "c, "_"c)
                .Add("?"c, "?"c)
                .Add("!"c, "!"c)
                .Add("-"c, "-"c)
                .Add("."c, "."c)
                .Add(","c, ","c)
            Else
                .Add("א"c, "a"c)
                .Add("ב"c, "b"c)
                .Add("ג"c, "c"c)
                .Add("ד"c, "d"c)
                .Add("ה"c, "e"c)
                .Add("ו"c, "f"c)
                .Add("ז"c, "g"c)
                .Add("ח"c, "h"c)
                .Add("ט"c, "i"c)
                .Add("י"c, "j"c)
                .Add("ך"c, "^"c)
                .Add("כ"c, "k"c)
                .Add("ל"c, "l"c)
                .Add("ם"c, "m"c)
                .Add("מ"c, "n"c)
                .Add("ן"c, "o"c)
                .Add("נ"c, "p"c)
                .Add("ס"c, "q"c)
                .Add("ע"c, "r"c)
                .Add("ף"c, "s"c)
                .Add("פ"c, "t"c)
                .Add("ץ"c, "u"c)
                .Add("צ"c, "v"c)
                .Add("ק"c, "w"c)
                .Add("ר"c, "x"c)
                .Add("ש"c, "y"c)
                .Add("ת"c, "z"c)
                .Add(" "c, "_"c)
                .Add("?"c, "?"c)
                .Add("!"c, "!"c)
                .Add("-"c, "-"c)
                .Add("."c, "."c)
                .Add(","c, ","c)
            End If
        End With
        Return dic
    End Function

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        TextBox2.Clear()

        Dim dic As Dictionary(Of Char, Char) = GetDic()
        Try
            For Each c As Char In TextBox1.Text
                TextBox2.AppendText(If(dic.ContainsKey(c), dic(c), c)) 'if char is not in dictionary append the original (such as newLine)
            Next
        Catch ex As Exception
            MsgBox(String.Format("Error occured:{0}{1}", vbNewLine, ex.Message))
        End Try

    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        About.Show()
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Close()
    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        TextBox1.Clear()
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        TextBox2.Clear()
    End Sub

    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
        If Clipboard.ContainsText = False Then MessageBox.Show("Paste failed, please try to copy again...", "Paste Failed", MessageBoxButtons.OK, MessageBoxIcon.Warning)
        If Not Clipboard.ContainsText = False Then TextBox1.Text = Clipboard.GetText
    End Sub

    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        Clipboard.Clear()
        If Not TextBox2.Text = "" Then Clipboard.SetText(TextBox2.Text)
        If TextBox2.Text = "" Then MessageBox.Show("Copy failed, there are no any text...", "Copy Failed", MessageBoxButtons.OK, MessageBoxIcon.Warning)
    End Sub

    Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click

        TextBox1.Clear()

        Dim dic As Dictionary(Of Char, Char) = GetDic()

        Try

            For Each c As Char In TextBox2.Text
                If dic.ContainsValue(c) Then
                    Dim curChar As Char = c 'declare variable to stop LINQ's whine
                    TextBox1.AppendText(dic.Where(Function(s) s.Value = curChar).First.Key)
                Else
                    TextBox1.AppendText(c)
                End If
            Next
        Catch ex As Exception
            MsgBox(String.Format("Error occured:{0}{1}", vbNewLine, ex.Message))
        End Try
    End Sub
End Class

Just one small thing: I want also to add an option to switch between the underline space (_) to a regular space ( ) .

thanks again
man1919.

That's easy.

if CheckBox2.Checked = True Then
                .Add(" "c, "_"c)
else
                .Add(" "c, " "c)
end if

use this instead of the

.Add(" "c, "_"c)

PS: You need a checkbox2 for this

That's easy.

if CheckBox2.Checked = True Then
                .Add(" "c, "_"c)
else
                .Add(" "c, " "c)
end if

use this instead of the

.Add(" "c, "_"c)

PS: You need a checkbox2 for this

Ok, thx its working, but i got also the untranslate button, so when i do untranslate it's do the opposite thing, for example:
if i place this intput:

PJQJFO_RM_XFFHJM

and i uncheck the Checkbox2 i got this output:

ניסיון_עם_רווחים

(which its mean test with space)
it's keeping the underlines.
so i tried to do this for the untranslation mode:

if CheckBox2.Checked = True Then
      .Add(" "c, "_"c)
      else
      .Add(" "c, " "c)
end if
if CheckBox3.Checked = True Then
      .Add("_"c, " "c)
      else
      .Add(" "c, " "c)
end if

but its not working, i get an error message (from the vb software).
what i can do for the untranslation mode?

and also
what i can do about the error message, that not showing up when there is an error (i try to make an error (for teset it), and its didnt show and error message) Maybe it's need to be MessageBox.Show instead ?

Ps: here is the full updated code again:

Public Class MainForm
    Private Function GetDic() As Dictionary(Of Char, Char)
        Dim dic As New Dictionary(Of Char, Char)
        With dic
            If Not CheckBox1.Checked = True Then
                .Add("א"c, "A"c)
                .Add("ב"c, "B"c)
                .Add("ג"c, "C"c)
                .Add("ד"c, "D"c)
                .Add("ה"c, "E"c)
                .Add("ו"c, "F"c)
                .Add("ז"c, "G"c)
                .Add("ח"c, "H"c)
                .Add("ט"c, "I"c)
                .Add("י"c, "J"c)
                .Add("ך"c, "^"c)
                .Add("כ"c, "K"c)
                .Add("ל"c, "L"c)
                .Add("ם"c, "M"c)
                .Add("מ"c, "N"c)
                .Add("ן"c, "O"c)
                .Add("נ"c, "P"c)
                .Add("ס"c, "Q"c)
                .Add("ע"c, "R"c)
                .Add("ף"c, "S"c)
                .Add("פ"c, "T"c)
                .Add("ץ"c, "U"c)
                .Add("צ"c, "V"c)
                .Add("ק"c, "W"c)
                .Add("ר"c, "X"c)
                .Add("ש"c, "Y"c)
                .Add("ת"c, "Z"c)
                .Add("?"c, "?"c)
                .Add("!"c, "!"c)
                .Add("-"c, "-"c)
                .Add("."c, "."c)
                .Add(","c, ","c)
            Else
                .Add("א"c, "a"c)
                .Add("ב"c, "b"c)
                .Add("ג"c, "c"c)
                .Add("ד"c, "d"c)
                .Add("ה"c, "e"c)
                .Add("ו"c, "f"c)
                .Add("ז"c, "g"c)
                .Add("ח"c, "h"c)
                .Add("ט"c, "i"c)
                .Add("י"c, "j"c)
                .Add("ך"c, "^"c)
                .Add("כ"c, "k"c)
                .Add("ל"c, "l"c)
                .Add("ם"c, "m"c)
                .Add("מ"c, "n"c)
                .Add("ן"c, "o"c)
                .Add("נ"c, "p"c)
                .Add("ס"c, "q"c)
                .Add("ע"c, "r"c)
                .Add("ף"c, "s"c)
                .Add("פ"c, "t"c)
                .Add("ץ"c, "u"c)
                .Add("צ"c, "v"c)
                .Add("ק"c, "w"c)
                .Add("ר"c, "x"c)
                .Add("ש"c, "y"c)
                .Add("ת"c, "z"c)
                .Add("?"c, "?"c)
                .Add("!"c, "!"c)
                .Add("-"c, "-"c)
                .Add("."c, "."c)
                .Add(","c, ","c)
            End If
            If CheckBox2.Checked = True Then
                .Add(" "c, "_"c)
            Else
                .Add(" "c, " "c)
            End If
        End With
        Return dic
    End Function

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        TextBox2.Clear()

        Dim dic As Dictionary(Of Char, Char) = GetDic()
        Try
            For Each c As Char In TextBox1.Text
                TextBox2.AppendText(If(dic.ContainsKey(c), dic(c), c)) 'if char is not in dictionary append the original (such as newLine)
            Next
        Catch ex As Exception
            MsgBox(String.Format("Error occured:{0}{1}", vbNewLine, ex.Message))
        End Try

    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        About.Show()
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Close()
    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        TextBox1.Clear()
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        TextBox2.Clear()
    End Sub

    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
        If Clipboard.ContainsText = False Then MessageBox.Show("Paste failed, please try to copy again...", "Paste Failed", MessageBoxButtons.OK, MessageBoxIcon.Warning)
        If Not Clipboard.ContainsText = False Then TextBox1.Text = Clipboard.GetText
    End Sub

    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        Clipboard.Clear()
        If Not TextBox2.Text = "" Then Clipboard.SetText(TextBox2.Text)
        If TextBox2.Text = "" Then MessageBox.Show("Copy failed, there are no any text...", "Copy Failed", MessageBoxButtons.OK, MessageBoxIcon.Warning)
    End Sub

    Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click

        TextBox1.Clear()

        Dim dic As Dictionary(Of Char, Char) = GetDic()

        Try

            For Each c As Char In TextBox2.Text
                If dic.ContainsValue(c) Then
                    Dim curChar As Char = c 'declare variable to stop LINQ's whine
                    TextBox1.AppendText(dic.Where(Function(s) s.Value = curChar).First.Key)
                Else
                    TextBox1.AppendText(c)
                End If
            Next
        Catch ex As Exception
            MsgBox(String.Format("Error occured:{0}{1}", vbNewLine, ex.Message))
        End Try
    End Sub
End Class

thx, man1919.

it is not completely clear to me about what error you are talking about and how you tried to raise it. but maybe the following code is more clear to you:

since we check if a character exist in a dictionary before we actually try to get the value there will never be an exception anyway.
"If dic.ContainsValue(c) Then" <<< if now this condition is false it will show a messagebox and break the loop.

Private Function GetDic() As Dictionary(Of Char, Char)
		Dim dic As New Dictionary(Of Char, Char)
		With dic
			.Add("א"c, "A"c)
			.Add("ב"c, "B"c)
			.Add("ג"c, "C"c)
			.Add("ד"c, "D"c)
			.Add("ה"c, "E"c)
			.Add("ו"c, "F"c)
			.Add("ז"c, "G"c)
			.Add("ח"c, "H"c)
			.Add("ט"c, "I"c)
			.Add("י"c, "J"c)
			.Add("ך"c, "^"c)
			.Add("כ"c, "K"c)
			.Add("ל"c, "L"c)
			.Add("ם"c, "M"c)
			.Add("מ"c, "N"c)
			.Add("ן"c, "O"c)
			.Add("נ"c, "P"c)
			.Add("ס"c, "Q"c)
			.Add("ע"c, "R"c)
			.Add("ף"c, "S"c)
			.Add("פ"c, "T"c)
			.Add("ץ"c, "U"c)
			.Add("צ"c, "V"c)
			.Add("ק"c, "W"c)
			.Add("ר"c, "X"c)
			.Add("ש"c, "Y"c)
			.Add("ת"c, "Z"c)
			.Add("?"c, "?"c)
			.Add("!"c, "!"c)
			.Add("-"c, "-"c)
			.Add("."c, "."c)
			.Add(","c, ","c)
		End With

		'convert to lower case if checkbox1 is not checked.
		If Not CheckBox1.Checked Then
			For Each value In dic.Values
				value = Char.ToLower(value)
			Next
		End If

		Return dic
	End Function

	Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

		TextBox2.Clear()

		Dim dic As Dictionary(Of Char, Char) = GetDic()
		For Each c As Char In TextBox1.Text
			If dic.ContainsKey(c) Then
				TextBox2.AppendText(dic(c))
			Else
				MsgBox(String.Format("The character {0} does not exist in the dictionary.", c))
				'break
				Exit For 
				'TextBox2.AppendText(c) 'if char is not in dictionary append the original (such as newLine)
			End If
		Next
	End Sub

	Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click

		TextBox1.Clear()

		Dim dic As Dictionary(Of Char, Char) = GetDic()

		For Each c As Char In TextBox2.Text
			If dic.ContainsValue(c) Then
				Dim curChar As Char = c	'declare variable to stop LINQ's whine
				TextBox1.AppendText(dic.Where(Function(s) s.Value = curChar).First.Key)
			Else
				MsgBox(String.Format("The character {0} does not exist in the dictionary.", c))
				'break
				Exit For 
				'TextBox1.AppendText(c) 'if char is not in dictionary append the original (such as newLine)
			End If
		Next
	End Sub

it is not completely clear to me about what error you are talking about and how you tried to raise it. but maybe the following code is more clear to you:

since we check if a character exist in a dictionary before we actually try to get the value there will never be an exception anyway.
"If dic.ContainsValue(c) Then" <<< if now this condition is false it will show a messagebox and break the loop.

Private Function GetDic() As Dictionary(Of Char, Char)
		Dim dic As New Dictionary(Of Char, Char)
		With dic
			.Add("א"c, "A"c)
			.Add("ב"c, "B"c)
			.Add("ג"c, "C"c)
			.Add("ד"c, "D"c)
			.Add("ה"c, "E"c)
			.Add("ו"c, "F"c)
			.Add("ז"c, "G"c)
			.Add("ח"c, "H"c)
			.Add("ט"c, "I"c)
			.Add("י"c, "J"c)
			.Add("ך"c, "^"c)
			.Add("כ"c, "K"c)
			.Add("ל"c, "L"c)
			.Add("ם"c, "M"c)
			.Add("מ"c, "N"c)
			.Add("ן"c, "O"c)
			.Add("נ"c, "P"c)
			.Add("ס"c, "Q"c)
			.Add("ע"c, "R"c)
			.Add("ף"c, "S"c)
			.Add("פ"c, "T"c)
			.Add("ץ"c, "U"c)
			.Add("צ"c, "V"c)
			.Add("ק"c, "W"c)
			.Add("ר"c, "X"c)
			.Add("ש"c, "Y"c)
			.Add("ת"c, "Z"c)
			.Add("?"c, "?"c)
			.Add("!"c, "!"c)
			.Add("-"c, "-"c)
			.Add("."c, "."c)
			.Add(","c, ","c)
		End With

		'convert to lower case if checkbox1 is not checked.
		If Not CheckBox1.Checked Then
			For Each value In dic.Values
				value = Char.ToLower(value)
			Next
		End If

		Return dic
	End Function

	Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

		TextBox2.Clear()

		Dim dic As Dictionary(Of Char, Char) = GetDic()
		For Each c As Char In TextBox1.Text
			If dic.ContainsKey(c) Then
				TextBox2.AppendText(dic(c))
			Else
				MsgBox(String.Format("The character {0} does not exist in the dictionary.", c))
				'break
				Exit For 
				'TextBox2.AppendText(c) 'if char is not in dictionary append the original (such as newLine)
			End If
		Next
	End Sub

	Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click

		TextBox1.Clear()

		Dim dic As Dictionary(Of Char, Char) = GetDic()

		For Each c As Char In TextBox2.Text
			If dic.ContainsValue(c) Then
				Dim curChar As Char = c	'declare variable to stop LINQ's whine
				TextBox1.AppendText(dic.Where(Function(s) s.Value = curChar).First.Key)
			Else
				MsgBox(String.Format("The character {0} does not exist in the dictionary.", c))
				'break
				Exit For 
				'TextBox1.AppendText(c) 'if char is not in dictionary append the original (such as newLine)
			End If
		Next
	End Sub

thank you, its working, its shows now the messages when there is an error occured, but the lower case mode are not working at all...

right, my fault.

add this function:

Private Function ConvertCase(c As Char) As Char
		Return If(checkbox1.checked, Char.ToLower(c), Char.ToUpper(c))
	End Function

and change the function GetDic to:

Private Function GetDic() As Dictionary(Of Char, Char)
		Dim dic As New Dictionary(Of Char, Char)
		With dic
			.Add("א"c, ConvertCase("A"c))
			.Add("ב"c, ConvertCase("B"c))
			.Add("ג"c, ConvertCase("C"c))
			.Add("ד"c, ConvertCase("D"c))
			.Add("ה"c, ConvertCase("E"c))
			.Add("ו"c, ConvertCase("F"c))
			.Add("ז"c, ConvertCase("G"c))
			.Add("ח"c, ConvertCase("H"c))
			.Add("ט"c, ConvertCase("I"c))
			.Add("י"c, ConvertCase("J"c))
			.Add("ך"c, ConvertCase("^"c))
			.Add("כ"c, ConvertCase("K"c))
			.Add("ל"c, ConvertCase("L"c))
			.Add("ם"c, ConvertCase("M"c))
			.Add("מ"c, ConvertCase("N"c))
			.Add("ן"c, ConvertCase("O"c))
			.Add("נ"c, ConvertCase("P"c))
			.Add("ס"c, ConvertCase("Q"c))
			.Add("ע"c, ConvertCase("R"c))
			.Add("ף"c, ConvertCase("S"c))
			.Add("פ"c, ConvertCase("T"c))
			.Add("ץ"c, ConvertCase("U"c))
			.Add("צ"c, ConvertCase("V"c))
			.Add("ק"c, ConvertCase("W"c))
			.Add("ר"c, ConvertCase("X"c))
			.Add("ש"c, ConvertCase("Y"c))
			.Add("ת"c, ConvertCase("Z"c))
			.Add("?"c, ConvertCase("?"c))
			.Add("!"c, ConvertCase("!"c))
			.Add("-"c, ConvertCase("-"c))
			.Add("."c, ConvertCase("."c))
			.Add(","c, ConvertCase(","c))
		End With


		Return dic
	End Function

ok, i done something around 90% of the program, just one small thing,
when i have a big text to translate and i translate him,
it's can cause the program to not respond (or get stuck) if someone press on the program window.
so i need something that will "lock" the all buttons or the all program window,
so its will prevent from the software to not respond.
i need also a progress bar that will indicate how much of the text has translated.

Thanks, Man1919.

locking the buttons won't help at all. as users prefer to click like headless chickens all over the place on a form.
So i suggest you to take a look at the Backgroundworker in order to get your translation done without loosing the response of your application.

Also your main concern about this thread is solved, so please mark this thread as solved.
thx

locking the buttons won't help at all. as users prefer to click like headless chickens all over the place on a form.
So i suggest you to take a look at the Backgroundworker in order to get your translation done without loosing the response of your application.

Also your main concern about this thread is solved, so please mark this thread as solved.
thx

Ok, Thank you very much for all your help! :), i am really appreciate it.

thx, man1919.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.