Gruppe
Dialog
Problem
Bei Eingabe einer 7-stelligen Zeichenfolge in eine UserForm-TextBox soll der String einer Textdatei gesucht werden. Bei Auffinden sind die Elemente des Datensatzes in Labels einzutragen.
ClassModule: frmSearch
Private Sub cmdCancel_Click()
Unload Me
End Sub
Private Sub txtSearch_Change()
Dim iCounter As Integer, iFile As Integer
Dim sFile As String, sTxt As String
sFile = ThisWorkbook.Path & "\Source.txt"
With txtSearch
If .TextLength = 7 Then
iFile = FreeFile
Open sFile For Input As iFile
Do Until EOF(iFile)
Line Input #1, sTxt
If Left(sTxt, 7) = .Text Then
Label1.Caption = Left(sTxt, 7)
Label2.Caption = Mid(sTxt, 8, 8)
Label3.Caption = Mid(sTxt, 16, 4)
Label4.Caption = Mid(sTxt, 20, 4)
Exit Do
End If
Loop
Close
If Label1.Caption = "" Then
For iCounter = 1 To 4
Controls("Label" & iCounter).Caption = "Nicht gefunden"
Next iCounter
End If
ElseIf .TextLength < 2 Then
For iCounter = 1 To 4
Controls("Label" & iCounter).Caption = ""
Next iCounter
End If
End With
End Sub
StandardModule: Modul1
Sub CallForm()
frmSearch.Show
End Sub