Potrzeboje opini/pomocy przy kodzie Visual Basic

0

Witam,
Mam kod w ktorym dodaje opcje jezykowe uzywajac if i else if, I chcialem sie dowiedziec czy nie prosciej by bylo uzyc switcha, tylko ze kod musze zmieniac w paru miejscach w zaleznosci jaki jezyk zostanie wybrany. Nie zjedzcie mnie od razu bo niebardzo wiem co robie ;P

 Private Sub btnConnect_Click(sender As System.Object, e As System.EventArgs) Handles btnConnect.Click
        '--English/////////////////////////////////////////////
        If ComboBox1.Text = "EN" Then
            If btnConnect.Text = "Disconnect" Then
                CloseOVPN()
                btnConnect.Text = "Connect"
                txtView.Text = ""
                Exit Sub
            End If
            If txtUser.Text = "" Or txtPass.Text = "" Then
                MessageBox.Show("Please fill empty fields!")
                Exit Sub
            End If
            '--Polish//////////////////////////////////////////
        ElseIf ComboBox1.Text = "PL" Then
            If btnConnect.Text = "Rozłącz" Then
                CloseOVPN()
                btnConnect.Text = "Połącz"
                txtView.Text = ""
                Exit Sub
            End If
            If txtUser.Text = "" Or txtPass.Text = "" Then
                MessageBox.Show("Proszę uzupełnic puste pola!")
                Exit Sub
            End If
            '--France///////////////////////////////////////
        ElseIf ComboBox1.Text = "FR" Then
            If btnConnect.Text = "Déconnecte" Then
                CloseOVPN()
                btnConnect.Text = "Relier"
                txtView.Text = ""
                Exit Sub
            End If
            If txtUser.Text = "" Or txtPass.Text = "" Then
                MessageBox.Show("S'il vous plaît remplir les champs vides!")
                Exit Sub
            End If
            '--German//////////////////////////////////////
        ElseIf ComboBox1.Text = "DE" Then
            If btnConnect.Text = "Trennen" Then
                CloseOVPN()
                btnConnect.Text = "Verbinden"
                txtView.Text = ""
                Exit Sub
            End If
            If txtUser.Text = "" Or txtPass.Text = "" Then
                MessageBox.Show("Bitte füllen leere Felder!")
                Exit Sub
            End If
            '--Spanish/////////////////////////////////////////
        ElseIf ComboBox1.Text = "ES" Then
            If btnConnect.Text = "Desconectar" Then
                CloseOVPN()
                btnConnect.Text = "Conecte"
                txtView.Text = ""
                Exit Sub
            End If
            If txtUser.Text = "" Or txtPass.Text = "" Then
                MessageBox.Show("Por favor, rellene los campos vacios!")
                Exit Sub
            End If
            '--Portuguese///////////////////////////////////////////////
        ElseIf ComboBox1.Text = "PT" Then
            If btnConnect.Text = "Disconnect" Then
                CloseOVPN()
                btnConnect.Text = "Conectar"
                txtView.Text = ""
                Exit Sub
            End If
            If txtUser.Text = "" Or txtPass.Text = "" Then
                MessageBox.Show("Por favor, preencha os campos vazio!")
                Exit Sub
            End If
            '--Italian////////////////////////////////////////////
        ElseIf ComboBox1.Text = "IT" Then
            If btnConnect.Text = "Scollegare" Then
                CloseOVPN()
                btnConnect.Text = "Collegare"
                txtView.Text = ""
                Exit Sub
            End If
            If txtUser.Text = "" Or txtPass.Text = "" Then
                MessageBox.Show("Si prega di compilare i campi vuoti!")
                Exit Sub
            End If
            '--Japan////////////////////////////////////////////
        ElseIf ComboBox1.Text = "JP" Then
            If btnConnect.Text = "切断" Then
                CloseOVPN()
                btnConnect.Text = "接続する"
                txtView.Text = ""
                Exit Sub
            End If
            If txtUser.Text = "" Or txtPass.Text = "" Then
                MessageBox.Show("空のフィールドを記入してください!")
                Exit Sub
            End If
            'Ukrainian//////////////////////////////////////////////
        ElseIf ComboBox1.Text = "UA" Then
            If btnConnect.Text = "відключіть" Then
                CloseOVPN()
                btnConnect.Text = "Підключіть"
                txtView.Text = ""
                Exit Sub
            End If
            If txtUser.Text = "" Or txtPass.Text = "" Then
                MessageBox.Show("Будь ласка, заповніть порожні поля!")
                Exit Sub
            End If
        End If


        Dim sw As New System.IO.StreamWriter(UserPath)
        sw.WriteLine(txtUser.Text)
        sw.WriteLine(txtPass.Text)
        sw.Close()

        CloseOVPN()

        txtView.Clear()


        Dim sinfo As New ProcessStartInfo
        With sinfo
            .FileName = OVPNExePath
            .Arguments = "--config """ & ConfigPath & "\" & cboServer.Text & ".ovpn"" --auth-user-pass """ & UserPath.Replace("\", "\\") & """"
            .Verb = "runas"
            .CreateNoWindow = True
            .UseShellExecute = False
            .RedirectStandardOutput = True
            '.RedirectStandardInput = True
            '.RedirectStandardError = True
        End With

        OUTPUT = ""
        Try
            proc.CancelOutputRead()
        Catch ex As Exception

        End Try

        proc.StartInfo = sinfo
        proc.Start()
        proc.BeginOutputReadLine()
    End Sub

    Private OUTPUT As String
    Private Sub outputReceive(sender As Object, args As DataReceivedEventArgs)
        If Not String.IsNullOrEmpty(args.Data) Then OUTPUT = args.Data
    End Sub
    Private Sub tmrCheckTick(sender As System.Object, e As System.EventArgs) Handles tmrCheck.Tick
        If OUTPUT <> "" Then
            Dim line As String = OUTPUT.Trim
            Static LastLine As String
            If LastLine <> line Then
                If InStr(line, "Completed") Then
                    'English/////////////////////////////////////////////////
                    If ComboBox1.Text = "EN" Then
                        txtView.Text &= vbNewLine & vbNewLine & "STATUS - CONNECTED" & vbNewLine
                        btnConnect.Text = "Disconnect"
                        'Polish/////////////////////////////////////////////
                    ElseIf ComboBox1.Text = "PL" Then
                        txtView.Text &= vbNewLine & vbNewLine & "STATUS - POŁĄCZONO" & vbNewLine
                        btnConnect.Text = "Rozłącz"
                        'France/////////////////////////////////////////////
                    ElseIf ComboBox1.Text = "FR" Then
                        txtView.Text &= vbNewLine & vbNewLine & "STATUS - CONNECTÉ" & vbNewLine
                        btnConnect.Text = "Déconnecte"
                        'German///////////////////////////////////////////////
                    ElseIf ComboBox1.Text = "DE" Then
                        txtView.Text &= vbNewLine & vbNewLine & "STATUS - VERBUNDEN" & vbNewLine
                        btnConnect.Text = "Trennen"
                        'Spanish////////////////////////////////////////////////
                    ElseIf ComboBox1.Text = "ES" Then
                        txtView.Text &= vbNewLine & vbNewLine & "STATUS - CONECTADO" & vbNewLine
                        btnConnect.Text = "Desconectar"
                        'Portuguese/////////////////////////////////////////////
                    ElseIf ComboBox1.Text = "PT" Then
                        txtView.Text &= vbNewLine & vbNewLine & "STATUS - CONECTADO" & vbNewLine
                        btnConnect.Text = "Desconectar"
                        'Italian///////////////////////////////////////////////
                    ElseIf ComboBox1.Text = "IT" Then
                        txtView.Text &= vbNewLine & vbNewLine & "STATUS - CONECTADO" & vbNewLine
                        btnConnect.Text = "Scollegare"
                        'Japan/////////////////////////////////////////////////
                    ElseIf ComboBox1.Text = "JP" Then
                        txtView.Text &= vbNewLine & vbNewLine & "STATUS - 接続" & vbNewLine
                        btnConnect.Text = "切断"
                        'Ukrainian//////////////////////////////////////////////
                    ElseIf ComboBox1.Text = "UA" Then
                        txtView.Text &= vbNewLine & vbNewLine & "STATUS - ПІДКЛЮЧЕННЯ" & vbNewLine
                        btnConnect.Text = "відключіть"
                    End If


                    OverwriteUser(True)
                ElseIf InStr(line, "auth-failure") Then
                    'English//////////////////////////////////////////////////////
                    If ComboBox1.Text = "EN" Then
                        txtView.Text &= vbNewLine & vbNewLine & "STATUS - WRONG USER/PASS" & vbNewLine
                        'Polish////////////////////////////////////////////////////
                    ElseIf ComboBox1.Text = "PL" Then
                        txtView.Text &= vbNewLine & vbNewLine & "STATUS - ZLE LOGIN/HASŁO" & vbNewLine
                        'France////////////////////////////////////////////////////////
                    ElseIf ComboBox1.Text = "FR" Then
                        txtView.Text &= vbNewLine & vbNewLine & "STATUS - FAUX PASSE/SERVEUR" & vbNewLine
                        'German//////////////////////////////////////////////////////
                    ElseIf ComboBox1.Text = "DE" Then
                        txtView.Text &= vbNewLine & vbNewLine & "STATUS - FALSCH LOGIN/PASSWORT" & vbNewLine
                        'Spanish/////////////////////////////////////////////////////
                    ElseIf ComboBox1.Text = "ES" Then
                        txtView.Text &= vbNewLine & vbNewLine & "STATUS - WRONG USARIO/PASS" & vbNewLine
                        'Portuguese/////////////////////////////////////////////////
                    ElseIf ComboBox1.Text = "PT" Then
                        txtView.Text &= vbNewLine & vbNewLine & "STATUS - ERRADO USARIO/PASSE" & vbNewLine
                        'Italian///////////////////////////////////////////////////
                    ElseIf ComboBox1.Text = "IT" Then
                        txtView.Text &= vbNewLine & vbNewLine & "STATUS - SBAGLIATO UTENTE/PASSO" & vbNewLine
                        'Japan///////////////////////////////////////////////////////
                    ElseIf ComboBox1.Text = "JP" Then
                        txtView.Text &= vbNewLine & vbNewLine & "STATUS - 間違った ユーザー/合格" & vbNewLine
                        'Ukrainian////////////////////////////////////////////////////////
                    ElseIf ComboBox1.Text = "UA" Then
                        txtView.Text &= vbNewLine & vbNewLine & "STATUS - НЕПРАВИЛЬНО Користувач/пройти" & vbNewLine
                        OverwriteUser(True)
                    End If
                Else
                    txtView.Text &= line & vbNewLine
                End If

                txtView.AppendText(txtView.Text)
                txtView.Select(txtView.TextLength, 0)
                txtView.ScrollToCaret()
                Application.DoEvents()
            End If
            LastLine = line
            End If
    End Sub

    Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
        'English//////////////////////////////////////////////
        If ComboBox1.Text = "EN" Then
            btnConnect.Text = "Connect"
            Label1.Text = "User:"
            Label2.Text = "Pass:"
            Label3.Text = "Server:"
            'Polish/////////////////////////////////////////
        ElseIf ComboBox1.Text = "PL" Then
            btnConnect.Text = "Polacz"
            Label1.Text = "Login:"
            Label2.Text = "Haslo:"
            Label3.Text = "Serwer:"
            'France/////////////////////////////////////////
        ElseIf ComboBox1.Text = "FR" Then
            btnConnect.Text = "Relier"
            Label1.Text = "Login:"
            Label2.Text = "Passe:"
            Label3.Text = "Serveur:"
            'German//////////////////////////////////////////
        ElseIf ComboBox1.Text = "DE" Then
            btnConnect.Text = "verbinden"
            Label1.Text = "Benutz:"
            Label2.Text = "Pass:"
            Label3.Text = "Server:"
            'Spanish//////////////////////////////////////////
        ElseIf ComboBox1.Text = "ES" Then
            btnConnect.Text = "Conecte"
            Label1.Text = "Usario:"
            Label2.Text = "Pass:"
            Label3.Text = "Servidor:"
            'Portuguese////////////////////////////////////////
        ElseIf ComboBox1.Text = "PT" Then
            btnConnect.Text = "Conectar"
            Label1.Text = "Usuario:"
            Label2.Text = "Passe:"
            Label3.Text = "Servidor:"
            'Italian////////////////////////////////////////////
        ElseIf ComboBox1.Text = "IT" Then
            btnConnect.Text = "Collegare"
            Label1.Text = "Utente:"
            Label2.Text = "Passo:"
            Label3.Text = "Server:"
            'Japan//////////////////////////////////////////////
        ElseIf ComboBox1.Text = "JP" Then
            btnConnect.Text = "接続する"
            Label1.Text = "ユーザー:"
            Label2.Text = "パス:"
            Label3.Text = "サーバー:"
            'Ukrainian///////////////////////////////////////////////
        ElseIf ComboBox1.Text = "UA" Then
            btnConnect.Text = "Підключіть"
            Label1.Text = "пройти:"
            Label2.Text = "пароль:"
            Label3.Text = "сервер:"
        End If
    End Sub
End Class
 
1

Nie, nie, nie.

button.text = dictionaryWithSentencesInChosenLanguage[CONNECT]

#EDIT:
@dam1an
user image

0

Potrzebny @Shalom i jego obrazek z grzybkiem :D

0

hehe zabawne, a moze byt tak pomoc troche? :P
Dopiero zaczynam zabawe z VB a wujek google mi za bardzo z tym nie pomogl.
Dzieki Spartan, chociaz nie bardzo wiem zamiast czego mam to wkleic bo mi error wyskakuje, potreba zaimportowac jakies biblioteki z tym zwiazane?

1

Chodzi o to, żebyś miał słownik z wyrażeniami - w ten sposób unikniesz tych warunkowych drzewek.

1

Jeszcze jedno proste, skuteczne podejscie: pliki properties z lokalizacja. Czyli np

en.lang
Label2.Text = "Pass:"
.
.
.

pl.lang
Label2.Text = "Hasło:"
.
.
.

Wczytujesz wtedy taki plik jak potrzebujesz i juz. Zaleta: latwo nowy jezyk dodac badz cos zmienic w tlumaczneiu (mozna to bez ponownej kompilacji zrobic).

0

Wielkie Dzieki za pomoc spartanPAGE i WhiteLightning zaraz sprobuje to ogarnac :)

1 użytkowników online, w tym zalogowanych: 0, gości: 1