Hi guys. Sorry I couldn't think of a more definitive title. I have a text file to which I have been appending points with their data. Now I want to list the file's information. However, there are gaps between points so the code below does not work properly unless there are no gaps. I am getting an 'Array out of bounds' error. Any ideas? I am adding the points to the file with this code:
The kind of file I am talking about would look like this
1,1000,1000,NONE
2,1027.699,1030.228,NONE
3,1030.228,1070.797,NONE
4,999.933,1081.15,NONE
11,1088.234,7654.987,NONE 'gaps appear between 4 and 11, 12 and 33
12,1345.234,3456.789,NONE
33,1023.456,8765.234,NONE
B4X:
Dim writer As TextWriter
writer.Initialize (File.openoutput(File.DirInternal,main.strfilename ,True))
writer.Write(main.strpointno & "," & main.dblnorth & "," & main.dbleast & "," & main.strdes & CRLF)
writer.Close
The kind of file I am talking about would look like this
1,1000,1000,NONE
2,1027.699,1030.228,NONE
3,1030.228,1070.797,NONE
4,999.933,1081.15,NONE
11,1088.234,7654.987,NONE 'gaps appear between 4 and 11, 12 and 33
12,1345.234,3456.789,NONE
33,1023.456,8765.234,NONE
B4X:
Sub btnOK_click
Dim crd()
'This is so all of the points in the file will list when the text box is empty
Dim reader As TextReader
reader.Initialize (File.openinput(File.DirInternal,main.strfilename ))
Dim lineoftext As String
Dim cline()
lineoftext=reader.ReadLine
Do While lineoftext<>Null
cline=Regex.Split (",",lineoftext)
txtdisplay.text=txtdisplay.text & cline(0) & " " & NumberFormat(cline(1),0,3) & " " & NumberFormat(cline(2),0,3) & " " & cline(3) & CRLF
lineoftext=reader.readline
Loop
reader.Close
End If
'when there is a range of points separated with a comma
Dim firstpt,lastpt,crd()
Dim reader As TextReader
reader.Initialize (File.openinput(File.DirInternal,main.strfilename ))
Dim lineoftext As String
Dim cline()
crd=Regex.Split(",",txtrange.Text )
firstpt=crd(0)
lastpt=crd(1)
lineoftext=reader.ReadLine
Do While lineoftext<>Null
cline=Regex.Split(",",lineoftext )
If cline(0)>=firstpt AND cline(0)<=lastpt Then
txtdisplay.Text = txtdisplay.Text & cline(0) & " " & NumberFormat(cline(1),0,3) & " " & NumberFormat(cline(2),0,3) & " " & cline(3) & CRLF
End If
lineoftext=reader.readline
Loop
reader.Close
End Sub