tramite questo codice mi permette di effettuare una ricerca su un file di testo, e tramite la procedura "TextFieldParser" posso leggere tutti i campi:
currentRow(0) legge la data e l'ora "29/12/2012 08.05.12";
currentRow(1) legge "Entrata" o "Uscita";
currentRow(2) legge "Cognome e Nome";
currentRow(4) legge "Motivo" (es. pausa pranzo);
currentRow(5) legge "FORD FIESTA AZ 504 BB" (ogni riferimento a qualcuno e puramente casuale)
etc. etc.
e li visualizzo nella "TextBox"
Domanda:
Quando faccio la ricerca mi legge solamente l'ultima stringa del file di testo, come posso far si che mi legga tutte le entrate ed uscite della persona selezionata ? mi potete aiutare in questo ? spero di essere stato chiaro.
posto il codice:
codice:Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Using MyReader As New Microsoft.VisualBasic.FileIO.TextFieldParser("C:\Accessi\ArchivioGenerale\ArchivioEntrateUscite.txt") MyReader.TextFieldType = FileIO.FieldType.Delimited MyReader.SetDelimiters("-") Dim currentRow As String() While Not MyReader.EndOfData Try currentRow = MyReader.ReadFields() Dim data = DateTime.ParseExact(currentRow(0), "dd/MM/yyyy H.mm.ss", Globalization.CultureInfo.InvariantCulture) Dim Ricerca As String Ricerca = TextBox1.Text If currentRow(2) = ComboBox2.Text Then If data.Date >= DateTimePicker1.Value.Date AndAlso data.Date <= DateTimePicker2.Value.Date Then TextBox1.Text = currentRow(0) & " " & currentRow(1) & " " & currentRow(2) & " " & currentRow(3) & " " & currentRow(4) & vbCrLf End If End If Catch ex As Microsoft.VisualBasic.FileIO.MalformedLineException MsgBox("Line " & ex.Message & "is not valid and will be skipped.") End Try End While End Using End Sub

Rispondi quotando