Public Class frmNacherfassungBelegNrEingabe

    Sub New(BelegNr)
        InitializeComponent()
        Me.BelegNr = BelegNr
    End Sub

    Public BelegNr = ""
    Private Sub MyTextBox1_TextChanged(sender As Object, e As EventArgs) Handles txtFreitext.TextChanged
        rbtnFreitext.Checked = True
    End Sub

    Private Sub MyTextBox23_TextChanged(sender As Object, e As EventArgs) Handles txtMRN6.TextChanged, txtMRN5.TextChanged, txtMRN4.TextChanged, txtMRN3.TextChanged, txtMRN2.TextChanged, txtMRN1.TextChanged
        rbtnMRN.Checked = True
    End Sub

    Private Sub MyTextBox15_TextChanged(sender As Object, e As EventArgs) Handles txtATC1.TextChanged, txtATC6.TextChanged, txtATC5.TextChanged, txtATC4.TextChanged, txtATC3.TextChanged, txtATC2.TextChanged, txtATC7.TextChanged
        rbtnATC.Checked = True
    End Sub

    Private Sub btnFertig_Click(sender As Object, e As EventArgs) Handles btnFertig.Click
        BelegNr = ""
        If rbtnATC.Checked Then
            BelegNr &= txtATC1.Text
            BelegNr &= txtATC2.Text
            BelegNr &= txtATC3.Text
            BelegNr &= txtATC4.Text
            BelegNr &= txtATC5.Text
            BelegNr &= txtATC6.Text
            BelegNr &= txtATC7.Text
            MsgBox(BelegNr.length)
            If Not BelegNr.length = 27 And Not BelegNr.length = 21 Then
                MsgBox("Format nicht korrekt!" & vbNewLine & "Bitte prüfen Sie die Eingabe.")
                Me.DialogResult = DialogResult.None
            End If
        ElseIf rbtnMRN.Checked Then
            BelegNr &= txtMRN1.Text
            BelegNr &= txtMRN2.Text
            BelegNr &= txtMRN3.Text
            BelegNr &= txtMRN4.Text
            BelegNr &= txtMRN5.Text
            BelegNr &= txtMRN6.Text
            MsgBox(BelegNr.length)
            If Not BelegNr.length = 23 And Not BelegNr.length = 18 Then
                MsgBox("Format nicht korrekt!" & vbNewLine & "Bitte prüfen Sie die Eingabe.")
                Me.DialogResult = DialogResult.None
            End If
        ElseIf rbtnFreitext.Checked Then
            BelegNr = txtFreitext.Text
        End If
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        BelegNr = ""
    End Sub

    Private Sub frmNacherfassungBelegNrEingabe_Load(sender As Object, e As EventArgs) Handles Me.Load

        '  Me!BelegNr1 = "AT"
        '  Me!BelegNr2 = "C"
        '  Me!BelegNr3 = "40"
        '  Me!BelegNr4 = Null
        txtATC5.Text = Format(Now, "mm")
        txtATC6.Text = Format(Now, "yyyy")
        '    Me!BelegNr7 = "7701"
        txtMRN1.Text = Format(Now, "yy")
        '    Me!MRN2 = "DE"
        '   Me!MRN3 = "7701"
        '   Me!MRN4 = Null
        '  Me!MRN5 = "M"
        '  Me!MRN6 = "0"
        If BelegNr <> "" Then

            If BelegNr.length = 27 Then
                txtATC1.Text = Mid(BelegNr, 1, 2)
                txtATC2.Text = Mid(BelegNr, 4, 1)
                txtATC3.Text = Mid(BelegNr, 6, 2)
                txtATC4.Text = Mid(BelegNr, 9, 6)
                txtATC5.Text = Mid(BelegNr, 16, 2)
                txtATC6.Text = Mid(BelegNr, 19, 4)
                txtATC7.Text = Mid(BelegNr, 24, 4)
                rbtnATC.Checked = True
            ElseIf BelegNr.length = 21 Then
                txtATC1.Text = Mid(BelegNr, 1, 2)
                txtATC2.Text = Mid(BelegNr, 3, 1)
                txtATC3.Text = Mid(BelegNr, 4, 2)
                txtATC4.Text = Mid(BelegNr, 6, 6)
                txtATC5.Text = Mid(BelegNr, 12, 2)
                txtATC6.Text = Mid(BelegNr, 14, 4)
                txtATC7.Text = Mid(BelegNr, 18, 4)
                rbtnATC.Checked = True
            ElseIf BelegNr.length = 23 Then
                txtMRN1.Text = Mid(BelegNr, 1, 2)
                txtMRN2.Text = Mid(BelegNr, 4, 2)
                txtMRN3.Text = Mid(BelegNr, 7, 4)
                txtMRN4.Text = Mid(BelegNr, 12, 8)
                txtMRN5.Text = Mid(BelegNr, 21, 1)
                txtMRN6.Text = Mid(BelegNr, 23, 1)
                rbtnMRN.Checked = True
            ElseIf BelegNr.length = 18 Then
                txtMRN1.Text = Mid(BelegNr, 1, 2)
                txtMRN2.Text = Mid(BelegNr, 3, 2)
                txtMRN3.Text = Mid(BelegNr, 5, 4)
                txtMRN4.Text = Mid(BelegNr, 9, 8)
                txtMRN5.Text = Mid(BelegNr, 17, 1)
                txtMRN6.Text = Mid(BelegNr, 18, 1)
                rbtnMRN.Checked = True
            Else
                txtFreitext.Text = BelegNr
                rbtnFreitext.Checked = True
            End If

        End If
    End Sub
End Class