I have a code where I search a text file for for example: "2320018200000", then it looks it up and finds a line like this:
"3 1604001Sf nyretalg 20 kgs frys00031000100142Test før: 00365001800009000000000000000000000000010000000Sf nyretalg 20 kgs frys0000000 2320018200000"
I want it to put that entire line in a label, but for some reason it skips the "3 1604001Sf" in the start. Here's my code:
Thanks in advance for your time.Code:Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim test = FindStringInFile("C:\Users\danl.FATLAND\Documents\vare.txt", TextBox1.Text) If test Then Dim cnstart = TextBox1.Text Dim lines = IO.File.ReadAllLines("C:\Users\danl.FATLAND\Documents\vare.txt") Dim ComputerName = (From firstline In lines Where firstline.Contains(cnstart)).First.Substring(cnstart.Length) Label2.Text = ComputerName Else MessageBox.Show("not found") End If End Sub Public Function FindStringInFile(ByVal Filename As String, ByVal SearchString As String) As Boolean Dim Reader As System.IO.StreamReader Reader = New IO.StreamReader(Filename) Dim readalllines As String Try While Reader.Peek <> -1 readalllines = Reader.ReadToEnd() If InStr(readalllines, SearchString) > 0 Then Return True End While Reader.Close() Return False Catch ex As Exception MessageBox.Show("Exception: " & ex.Message) Return False End Try End Function




Reply With Quote