How to Find Max Value of X, Y ,Z From Text file Using VB.Net
.vb Code
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Windows.Forms
Imports System.IO
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Button1.Click
Dim Lines As String() = File.ReadAllLines("TextFile1.txt")
Dim maxZ As Integer = 0
For Each line As String In Lines
Dim SplitString As String() = line.Split(" "c)
If SplitString.Length > 2 Then
Try
If Integer.Parse(SplitString(2)) > maxZ Then
maxZ = Integer.Parse(SplitString(2))
End If
Catch
End Try
End If
Next
TextBox2.Text = maxZ.ToString()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Button2.Click
Dim Lines As String() = File.ReadAllLines("TextFile1.txt")
Dim maxX As Integer = 0
For Each line As String In Lines
Dim SplitString As String() = line.Split(" "c)
If SplitString.Length > 3 Then
Try
If Integer.Parse(SplitString(3)) > maxX Then
maxX = Integer.Parse(SplitString(3))
End If
Catch
End Try
End If
Next
TextBox3.Text = maxX.ToString()
End Sub
Private Sub btnFindMaxY_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles btnFindMaxY.Click
Dim Lines As String() = File.ReadAllLines("TextFile1.txt")
Dim maxY As Integer = 0
For Each line As String In Lines
Dim SplitString As String() = line.Split(" "c)
If SplitString.Length > 1 Then
Try
If Integer.Parse(SplitString(1)) > maxY Then
maxY = Integer.Parse(SplitString(1))
End If
Catch
End Try
End If
Next
TextBox1.Text = maxY.ToString()
End Sub
End Class
Design
Create Text file Like This