Public Class Form1
Dim path As String = ""
Public Taal As String = ""
Dim Path2() As String = {"C:\Helpmij\Talen\", "SelectedLanguagePath.txt"}
Dim DefaultTaal() As String = {"", "De 'Opslaan' functie heb ik niet gemaakt omdat het gewoon een voorbeeld is.", "De 'Opslaan als' functie heb ik niet gemaakt omdat het gewoon een voorbeeld is.", "De 'Open' functie heb ik niet gemaakt omdat het gewoon een voorbeeld is.", "Hallo,", "Welkom in mijn Form...", "Verken de boel een beetje (al is het niet veel)[ENTER]en probeer eens veranderingen door te voeren in de textfile[ENTER]en zie dat het in het form ook veranderd.", "Er is geen taalfile gevonden,[ENTER]wilt u een taalfile selecteren?", "De geselecteerde textfile wordt niet gebruikt door dit programma,[ENTER]wilt u een andere selecteren?", "Help is niet beschikbaar zonder geselecteerde taal.", "Wil u ook meteen een taal selecteren uit deze file?"}
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
On Error Resume Next
If Not My.Computer.FileSystem.DirectoryExists(Path2(0)) Then My.Computer.FileSystem.CreateDirectory(Path2(0)) Else path = Split(My.Computer.FileSystem.ReadAllText(Path2(0) & Path2(1)), Chr(10))(0) : Taal = Split(My.Computer.FileSystem.ReadAllText(Path2(0) & Path2(1)), Chr(10))(1)
My.Computer.FileSystem.WriteAllText(Path2(0) & Path2(1), path & Chr(10) & Taal, False)
ResetEverything()
End Sub
Sub SetText(ByVal Ctrl As Control)
On Error GoTo err
If TypeOf Ctrl Is Label Then
Dim gettext As String = My.Computer.FileSystem.ReadAllText(path)
gettext = Split(Split(gettext, "<Taal='" & Taal & "'>")(1), "</Taal>")(0)
gettext = Split(Split(gettext, "<Labels>")(1), "</Labels>")(0)
gettext = Split(gettext, "/" & Ctrl.Name & " = ")(1)
gettext = Split(gettext, Chr(34))(1) 'chr(34) = een dubbele appestrof: "
Ctrl.Text = gettext
End If
If TypeOf Ctrl Is Button Then
Dim gettext As String = My.Computer.FileSystem.ReadAllText(path)
gettext = Split(Split(gettext, "<Taal='" & Taal & "'>")(1), "</Taal>")(0)
gettext = Split(Split(gettext, "<Buttons>")(1), "</Buttons>")(0)
gettext = Split(gettext, "/" & Ctrl.Name & " = ")(1)
gettext = Split(gettext, Chr(34))(1) 'chr(34) = een dubbele appestrof: "
Ctrl.Text = gettext
End If
err:
End Sub
Sub SetMenuText(ByVal tsmi As ToolStripMenuItem)
On Error GoTo err
Dim gettext As String = My.Computer.FileSystem.ReadAllText(path)
gettext = Split(Split(gettext, "<Taal='" & Taal & "'>")(1), "</Taal>")(0)
gettext = Split(Split(gettext, "<MenuItems>")(1), "</MenuItems>")(0)
gettext = Split(gettext, "/" & tsmi.Name & " = ")(1)
gettext = Split(gettext, Chr(34))(1) 'chr(34) = een dubbele appestrof: "
tsmi.Text = gettext
err:
End Sub
'menuknoppen
Private Sub M1_1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles M1_1.Click
Message(1)
End Sub
Private Sub M1_2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles M1_2.Click
Message(2)
End Sub
Private Sub M1_3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles M1_3.Click
Message(3)
End Sub
Private Sub M2_1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles M2_1.Click
ShowHelp()
End Sub
Private Sub M2_2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles M2_2.Click
On Error GoTo niet_goed
Dim gettext As String = My.Computer.FileSystem.ReadAllText(path)
gettext = Split(Split(gettext, "<TestCode>")(1), "</TestCode>")(0)
If gettext = "123456789" Then
TaalSelect.Show()
Dim pos As Point = Me.Location
pos.X += 225
If pos.X > 1025 Then pos.X -= 490
With TaalSelect
.Location = pos
End With
End If
Exit Sub
niet_goed:
If Message(7, MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then OpenFileDialog1.ShowDialog()
End Sub
Private Sub M2_3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles M2_3.Click
OpenFileDialog1.ShowDialog()
End Sub
Function Message(ByVal index As Integer, Optional ByVal buttons As MsgBoxStyle = MsgBoxStyle.OkOnly) As MsgBoxResult
On Error GoTo err
Dim gettext As String = My.Computer.FileSystem.ReadAllText(path)
gettext = Split(Split(gettext, "<Taal='" & Taal & "'>")(1), "</Taal>")(0)
gettext = Split(Split(gettext, "<Messages>")(1), "</Messages>")(0)
gettext = Split(gettext, "/msg_" & index & " = ")(1)
gettext = Split(gettext, Chr(34))(1) 'chr(34) = een dubbele appestrof: "
GoTo ver
err:
gettext = DefaultTaal(index)
ver:
gettext = Replace(gettext, "[ENTER]", Chr(10))
Dim res As MsgBoxResult
res = MsgBox(gettext, buttons)
Return res
End Function
Function ShowHelp(Optional ByVal buttons As MsgBoxStyle = MsgBoxStyle.OkOnly) As MsgBoxResult
On Error GoTo err
Dim gettext As String = My.Computer.FileSystem.ReadAllText(path)
gettext = Split(Split(gettext, "<Taal='" & Taal & "'>")(1), "</Taal>")(0)
gettext = Split(Split(gettext, "<Help>")(1), "</Help>")(0)
Dim res = MsgBox(gettext, buttons)
Return res
err:
Message(9)
End Function
Private Sub B1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles B1.Click
Message(4)
Message(5)
Message(6)
End Sub
Private Sub OpenFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk
On Error GoTo niet_goed
Dim gettext As String = My.Computer.FileSystem.ReadAllText(OpenFileDialog1.FileName())
gettext = Split(Split(gettext, "<TestCode>")(1), "</TestCode>")(0)
On Error Resume Next
If gettext = "123456789" Then
path = OpenFileDialog1.FileName()
My.Computer.FileSystem.WriteAllText(Path2(0) & Path2(1), path & Chr(10) & Taal, False)
If Message(10, MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
TaalSelect.Show()
Dim pos As Point = Me.Location
pos.X += 225
If pos.X > 1025 Then pos.X -= 530
TaalSelect.Location = pos
End If
Exit Sub 'zodat er geen melding wordt gegeven
End If
niet_goed:
If Message(8, MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then OpenFileDialog1.ShowDialog()
End Sub
Public Sub ResetEverything()
SetText(B1)
SetText(L1)
SetMenuText(M1_0)
SetMenuText(M1_1)
SetMenuText(M1_2)
SetMenuText(M1_3)
SetMenuText(M2_0)
SetMenuText(M2_1)
SetMenuText(M2_2)
End Sub
End Class