How can i get the points coordinates from text file with using Visual Basic?

  • Thread starter Thread starter secking13
  • Start date Start date
S

secking13

Guest
I would like get points coordinates from text file. Text file is too long. You can find a sample at below.


SAMPLE TEXT


POINTS Data


$$


ID X Y Z
POINTS 1 -5.15315 0.0 0.0


POINTS 2 -5.15315 0.0 0.0


POINTS 3 0.0 100.0 0.0


POINTS 4 100.0 100.0 0.0


POINTS 5 100.0 0.0 0.0


POINTS 6 100.0 105.325 200.0


POINTS 7 100.0 100.0 200.0


POINTS 8 -2.13-14 100.0 0.0


POINTS 9 100.0-1.42-14 0.0


POINTS 10 1.421-14-2.84-14 0.0


POINTS 11 -2.13-14 100.0 0.0


$$ --------------------------------------------------------------------------------$ $$ Group Definitions $ $$------------------------------------------------------------------------------$


Firstly i am not good at coding if you show me simply, i will be appreciated.


The aim is to get points id and coordinates.


1-read all the text file. 2-find the text length(row counts) 3-Create a for loop which starts 0 to (row counts) 4-detect the lines which starts with "POINTS" ( I thought to use mid(lines(i)),0,5)="POINTS") 5-Then use if mid(lines(i)),0,5)="POINTS" then mid(lines(i)),25,33)=cord(i) 6-Finally write this array to a text file.


The code i tried to this however it fails.


I am using visual studio 2019. Best regards


Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim myfilepath, test, test1, test2, i, strline


If OpenFileDialog1.ShowDialog = DialogResult.OK Then
myfilepath = OpenFileDialog1.FileName
End If
Dim cordx()
Dim cordy()
Dim cordz()


Dim satirlar = IO.File.ReadAllLines(myfilepath).Length
MsgBox(satirlar)
Dim lines = IO.File.ReadAllLines(myfilepath).ToList
For i = 0 To satirlar
If lines(i).ToLower.StartsWith("points") Then
cordx(i) = Mid(lines(i), 25, 33)
End If
Next


MsgBox(cordx)


End Sub
End Class

Continue reading...
 
Back
Top