I have several lines of data like this in a file
1,1000,1000,point1
2,1027.699,1030.228,point2
3,1045.671,1070.345,point3
4,2345.123,1098.346,point4
.
.
etc.
When I enter a point number in the txtFrom.text box and click my OK button, the code should go through the file until it finds that point number and attach the other data (dblnorth,dbleast) to it. Then I want to resume from where I called the sub (getcoord) and use the recovered data in calculations. My problem is that I don't know how to properly leave the sub after getting what I want. I can't use 'Goto or 'exit sub' so I need some method to accomplish this. Here is the code so far:
Incidentally, when the loop encounters the end of the data, it throws a null exception error. How do I prevent that? I will be using this type of code frequently during my application.
Any help or reference to help will be greatly appreciated.
Jim Schuchert
1,1000,1000,point1
2,1027.699,1030.228,point2
3,1045.671,1070.345,point3
4,2345.123,1098.346,point4
.
.
etc.
When I enter a point number in the txtFrom.text box and click my OK button, the code should go through the file until it finds that point number and attach the other data (dblnorth,dbleast) to it. Then I want to resume from where I called the sub (getcoord) and use the recovered data in calculations. My problem is that I don't know how to properly leave the sub after getting what I want. I can't use 'Goto or 'exit sub' so I need some method to accomplish this. Here is the code so far:
B4X:
Sub getcoord()
Dim reader As TextReader
reader.Initialize (File.openinput(File.DirInternal,main.strfilename ))
Dim lineoftext As String
Dim cline()
'get first line
lineoftext=reader.readline
cline=regex.split(",",lineoftext)
if cline(0)=txtFrom.text then
main.dblnorth=cline(1)
main.dbleast=cline(2)
[color=red]found it in first line soi want to leave this sub and go make calculations. In B4ppc I could use a 'Goto" command but not in B4a [/color]
End If
'If the first line does not contain what I want I will go through the rest of the file until I find the correct point number
Do While lineoftext<>Null
lineoftext=reader.ReadLine
cline=Regex.Split(",",lineoftext)
If cline(0)=txtfrom.Text Then
main.strpointno=cline(0)
main.dblnorth=cline(1)
main.dbleast=cline(2)
[color=red]same story as above. I need to use what I found somewhere else in the app[/color]
End If
Loop
reader.Close
End Sub
Incidentally, when the loop encounters the end of the data, it throws a null exception error. How do I prevent that? I will be using this type of code frequently during my application.
Any help or reference to help will be greatly appreciated.
Jim Schuchert