Guten Tag Zusammen,
Ich habe hier ein Snippet aus meinem Programm welches eine Datei einliest welche zuvor angeklickt wurde und dann den Inhalt ins Programm lädt und in die gegebenen Felder abfüllt. Da habe ich noch nicht alles gemacht der Übersichtshalber aber bevor ich dies vervollständige möchte ich euch fragen wo und wie ich korrekt Fehler abfangen kann. Bei einem Testlauf habe ich immer Fehler mit dem Datumsformat darum würde ich dieses gerne abfangen und überspringen falls es zu einem Fehler kommt. Try-Catch ging nicht, weil die Variable nacher weiterverwendet wird oder bereits vorher genutzt wird...
Spoiler anzeigen
Ich habe hier ein Snippet aus meinem Programm welches eine Datei einliest welche zuvor angeklickt wurde und dann den Inhalt ins Programm lädt und in die gegebenen Felder abfüllt. Da habe ich noch nicht alles gemacht der Übersichtshalber aber bevor ich dies vervollständige möchte ich euch fragen wo und wie ich korrekt Fehler abfangen kann. Bei einem Testlauf habe ich immer Fehler mit dem Datumsformat darum würde ich dieses gerne abfangen und überspringen falls es zu einem Fehler kommt. Try-Catch ging nicht, weil die Variable nacher weiterverwendet wird oder bereits vorher genutzt wird...
VB.NET-Quellcode
- Imports System.IO
- Imports System.Linq
- Imports System.Environment
- Public Class FormAutoComplete
- 'Dim Dateiliste() As String = System.IO.Directory.GetFiles(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & "\Dokumente\Indexierung", "*.*", System.IO.SearchOption.TopDirectoryOnly)
- Public scrWidth As Integer = Screen.PrimaryScreen.Bounds.Width
- Public scrHeight As Integer = Screen.PrimaryScreen.Bounds.Height
- Public poswid As Integer = scrWidth \ 2
- Public poswidi As Integer = poswid - 467
- Public poshei As Integer = scrHeight \ 2
- Public _isbestkeyword As String = ""
- Public _iskeyword As Boolean
- Public woerterbuchS As New List(Of String)
- Public appData As String = GetFolderPath(SpecialFolder.ApplicationData)
- Public path As String = appData & "\Dokumente"
- Public Sub myForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
- Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
- Me.ListBox1.Dock = DockStyle.Fill
- End Sub
- Private Sub ListBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
- _isbestkeyword = Me.ListBox1.Items(Me.ListBox1.SelectedIndex)
- End Sub
- Protected Overrides ReadOnly Property ShowWithoutActivation() As Boolean
- Get
- Return True
- End Get
- End Property
- Public i As Integer = 0
- Public Sub RefreshList(ByVal key As String)
- Dim Files = New System.IO.DirectoryInfo(path + "\Indexierung").GetFiles("*.*", IO.SearchOption.TopDirectoryOnly)
- While i <> 1
- woerterbuchS.AddRange(Files.Select(Function(f) f.Name).ToArray())
- i = i + 1
- End While
- Dim LA() As String
- LA = woerterbuchS.ToArray
- Dim all = LA.Length
- Me.ListBox1.Items.Clear()
- find_key_arg = key & "*"
- Dim t() As String
- t = Array.FindAll(LA, AddressOf find_key)
- If t.Count > 0 Then
- If key = "" Or t(t.Length - 1) = key Then
- _iskeyword = False
- Me.ListBox1.Items.Clear()
- Me.Hide()
- Else
- _iskeyword = True
- Me.ListBox1.Items.Clear()
- Me.ListBox1.Items.AddRange(t)
- Me.ListBox1.SelectedIndex = 0
- Me.Show()
- End If
- Else
- _iskeyword = False
- Me.Hide()
- End If
- End Sub
- Private Sub Main_LocationChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.LocationChanged
- Me.Location = New Point(Main.Location.X - Me.Width, Main.Location.Y)
- End Sub
- Private Sub listBox1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.DoubleClick
- Try
- Dim ValCon As Date
- Dim ValCon2 As Date
- Dim Valcon3 As Date
- Dim reader = My.Computer.FileSystem.ReadAllText(path & "\Indexierung\" + IsBestKeyWord)
- Dim parts = reader.Split(";"c)
- Dim part12 = parts(40).ToString.Split(" "c)
- Dim tripple2 = part12(0).Split("."c)
- Main.RichTextBox1.Text = parts(0)
- Main.RichTextBox2.Text = parts(1)
- Main.RichTextBox3.Text = parts(2)
- Main.RichTextBox4.Text = parts(3)
- Dim part1 = parts(4).ToString.Split(" "c)
- Dim tripple = part1(0).Split("."c)
- Dim EndDate As String = tripple(0) + "/" + tripple(1) + "/" + tripple(2)
- ValCon = Date.ParseExact(EndDate, "dd/MM/yyyy", System.Globalization.DateTimeFormatInfo.InvariantInfo, Globalization.DateTimeStyles.None)
- Main.DateTimePicker2.Value = ValCon
- Main.RichTextBox5.Text = parts(5)
- Main.RichTextBox6.Text = parts(6)
- Main.RichTextBox7.Text = parts(7)
- Main.RichTextBox8.Text = parts(8)
- Main.TextBox9.Text = parts(9)
- Main.TextBox1.Text = parts(10)
- Main.ComboBox12.SelectedIndex = -1
- Main.ComboBox12.SelectedText = parts(14).ToString
- Main.TextBox10.Text = parts(15)
- Main.TextBox11.Text = parts(16)
- Main.RichTextBox9.Text = parts(17)
- If parts(18).ToString = "True" Then
- Main.CheckBox1.Checked = True
- Else
- End If
- If parts(19).ToString = "Frei" Then
- Main.RadioButton1.Select()
- Else
- Main.RadioButton2.Select()
- End If
- Main.RichTextBox13.Text = parts(20)
- Main.RichTextBox11.Text = parts(21)
- Main.TextBox4.Text = parts(22)
- Main.TextBox8.Text = parts(23)
- Main.TextBox2.Text = parts(24)
- Main.TextBox5.Text = parts(25)
- Main.TextBox6.Text = parts(26)
- Main.TextBox7.Text = parts(27)
- Main.TextBox3.Text = parts(28)
- Main.ComboBox21.SelectedIndex = -1
- Main.ComboBox21.SelectedText = parts(29).ToString
- Main.ComboBox16.SelectedIndex = -1
- Main.ComboBox16.SelectedText = parts(30).ToString
- Main.ComboBox20.SelectedIndex = -1
- Main.ComboBox20.SelectedText = parts(31).ToString
- Main.ComboBox7.SelectedIndex = -1
- Main.ComboBox7.SelectedText = parts(32).ToString
- Main.ComboBox9.SelectedIndex = -1
- Main.ComboBox9.SelectedText = parts(33).ToString
- Main.ComboBox15.SelectedIndex = -1
- Main.ComboBox15.SelectedText = parts(34).ToString
- Main.ComboBox22.SelectedIndex = -1
- Main.ComboBox22.SelectedText = parts(35).ToString
- Main.RichTextBox12.Text = parts(36)
- Main.RichTextBox10.Text = parts(37)
- Main.ComboBox4.SelectedIndex = -1
- Main.ComboBox4.SelectedText = parts(38).ToString
- Main.TextBox12.Text = parts(39)
- Dim EndDate2 As String = tripple2(0) + "/" + tripple2(1) + "/" + tripple2(2)
- ValCon2 = Date.ParseExact(EndDate2, "dd/MM/yyyy", System.Globalization.DateTimeFormatInfo.InvariantInfo, Globalization.DateTimeStyles.None)
- Main.DateTimePicker1.Value = ValCon2
- Main.RichTextBox14.Text = parts(41)
- Main.RichTextBox15.Text = parts(42)
- Main.RichTextBox16.Text = parts(43)
- Dim part13 = parts(44).ToString.Split(" "c)
- Dim tripple3 = part13(0).Split("."c)
- Dim EndDate3 As String = tripple3(0) + "/" + tripple3(1) + "/" + tripple3(2)
- Valcon3 = Date.ParseExact(EndDate3, "dd/MM/yyyy", System.Globalization.DateTimeFormatInfo.InvariantInfo, Globalization.DateTimeStyles.None)
- Main.DateTimePicker3.Value = Valcon3
- Main.ComboBox2.SelectedIndex = -1
- Main.ComboBox2.SelectedText = parts(45).ToString
- Catch Ex As Exception
- MsgBox("Fehler beim abfüllen der Daten")
- MsgBox(Ex.ToString)
- End Try
- End Sub
- Public ReadOnly Property IsKeyWord() As Boolean
- Get
- Return _iskeyword
- End Get
- End Property
- Public ReadOnly Property IsBestKeyWord() As String
- Get
- If _iskeyword = True Then
- Return _isbestkeyword
- Else
- Return ""
- End If
- End Get
- End Property
- Private find_key_arg As String
- Private Function find_key(ByVal s As String) As Boolean
- If s Like find_key_arg Then
- Return True
- Else
- Return False
- End If
- End Function
- Dim ValCon As Date
- Dim ValCon2 As Date
- Dim Valcon3 As Date
- Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
- Try
- Dim ValCon As Date
- Dim ValCon2 As Date
- Dim Valcon3 As Date
- Dim reader = My.Computer.FileSystem.ReadAllText(path & "\Indexierung\" + IsBestKeyWord)
- Dim parts = reader.Split(";"c)
- Main.RichTextBox1.Text = parts(0)
- Main.RichTextBox2.Text = parts(1)
- Main.RichTextBox3.Text = parts(2)
- Main.RichTextBox4.Text = parts(3)
- Dim part1 = parts(4).ToString.Split(" "c)
- Dim tripple = part1(0).Split("."c)
- Dim EndDate As String = tripple(0) + "/" + tripple(1) + "/" + tripple(2)
- ValCon = Date.ParseExact(EndDate, "dd/MM/yyyy", System.Globalization.DateTimeFormatInfo.InvariantInfo, Globalization.DateTimeStyles.None)
- Main.DateTimePicker2.Value = ValCon
- Main.RichTextBox5.Text = parts(5)
- Main.RichTextBox6.Text = parts(6)
- Main.RichTextBox7.Text = parts(7)
- Main.RichTextBox8.Text = parts(8)
- Main.TextBox9.Text = parts(9)
- Main.TextBox1.Text = parts(10)
- Main.ComboBox12.SelectedText = parts(14).ToString
- Main.TextBox10.Text = parts(15)
- Main.TextBox11.Text = parts(16)
- Main.RichTextBox9.Text = parts(17)
- If parts(18).ToString = "True" Then
- Main.CheckBox1.Checked = True
- Else
- End If
- If parts(19).ToString = "Frei" Then
- Main.RadioButton1.Select()
- Else
- Main.RadioButton2.Select()
- End If
- Main.RichTextBox13.Text = parts(20)
- Main.RichTextBox11.Text = parts(21)
- Main.TextBox4.Text = parts(22)
- Main.TextBox8.Text = parts(23)
- Main.TextBox2.Text = parts(24)
- Main.TextBox5.Text = parts(25)
- Main.TextBox6.Text = parts(26)
- Main.TextBox7.Text = parts(27)
- Main.TextBox3.Text = parts(28)
- Main.ComboBox21.SelectedIndex = -1
- Main.ComboBox21.SelectedText = parts(29).ToString
- Main.ComboBox16.SelectedIndex = -1
- Main.ComboBox16.SelectedText = parts(30).ToString
- Main.ComboBox20.SelectedIndex = -1
- Main.ComboBox20.SelectedText = parts(31).ToString
- Main.ComboBox7.SelectedIndex = -1
- Main.ComboBox7.SelectedText = parts(32).ToString
- Main.ComboBox9.SelectedIndex = -1
- Main.ComboBox9.SelectedText = parts(33).ToString
- Main.ComboBox15.SelectedIndex = -1
- Main.ComboBox15.SelectedText = parts(34).ToString
- Main.ComboBox22.SelectedIndex = -1
- Main.ComboBox22.SelectedText = parts(35).ToString
- Main.RichTextBox12.Text = parts(36)
- Main.RichTextBox10.Text = parts(37)
- Main.ComboBox4.SelectedIndex = -1
- Main.ComboBox4.SelectedText = parts(38).ToString
- Main.TextBox12.Text = parts(39)
- Dim part12 = parts(40).ToString.Split(" "c)
- Dim tripple2 = part12(0).Split("."c)
- Dim EndDate2 As String = tripple2(0) + "/" + tripple2(1) + "/" + tripple2(2)
- ValCon2 = Date.ParseExact(EndDate2, "dd/MM/yyyy", System.Globalization.DateTimeFormatInfo.InvariantInfo, Globalization.DateTimeStyles.None)
- Main.DateTimePicker1.Value = ValCon2
- Main.RichTextBox14.Text = parts(41)
- Main.RichTextBox15.Text = parts(42)
- Main.RichTextBox16.Text = parts(43)
- Dim part13 = parts(44).ToString.Split(" "c)
- Dim tripple3 = part13(0).Split("."c)
- Dim EndDate3 As String = tripple3(0) + "/" + tripple3(1) + "/" + tripple3(2)
- Valcon3 = Date.ParseExact(EndDate3, "dd/MM/yyyy", System.Globalization.DateTimeFormatInfo.InvariantInfo, Globalization.DateTimeStyles.None)
- Main.DateTimePicker3.Value = Valcon3
- Main.ComboBox2.SelectedIndex = -1
- Main.ComboBox2.SelectedText = parts(45).ToString
- Catch Ex As Exception
- MsgBox("Fehler beim abfüllen der Daten")
- MsgBox(Ex.ToString)
- End Try
- End Sub
- End Class