I have the following question. I have a text file (shown below) and it contains a couple of lines, where each line is separated in 3 parts with a colon. What I would like to do is search the first part of the lines for specific content and use only those lines to calculate the last part of the lines.
1:test1:3
2:test2:5
3:test3:6
4:test4:9
5:test5:8
6:test6:7
For example lines with in the first part 1,3 and 6, calculate the total of the third part of these lines,that would be 16. The same for 2,4 and 5 tahta would be 22. The code I used so far:
1:test1:3
2:test2:5
3:test3:6
4:test4:9
5:test5:8
6:test6:7
For example lines with in the first part 1,3 and 6, calculate the total of the third part of these lines,that would be 16. The same for 2,4 and 5 tahta would be 22. The code I used so far:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim AllText As String = "", LineOfText As String = ""
Dim split(2) As String
OpenFileDialog1.Filter = "Text files (*.TXT)|*.TXT"
OpenFileDialog1.ShowDialog() 'display Open dialog box
If OpenFileDialog1.FileName <> "" Then
Try 'open file and trap any errors using handler
FileOpen(1, OpenFileDialog1.FileName, OpenMode.Input)
Do Until EOF(1) 'read lines from file
LineOfText = LineInput(1)
split = LineOfText.Split(":")
'add each line to the AllText variable
AllText = AllText & split(0) & " " & split(1) & " " & split(2) & vbCrLf
Loop
TextBox1.Text = AllText 'display file
Catch
MsgBox("Error opening file.")
Finally
FileClose(1) 'close file
End Try
End If
End Sub
End Class