I have been at this for 3 hours now and must get to bed but I am sure someone will see what I have done wrong. I am doing as much porting of my b4ppc code as possible into b4a but this one really has me stumped. the routine finds the coordinates of points entered in a textbox, then cross multiplies them to find an area. The ppc code works beautifully. Please review code below:
code from b4ppc
'b4a code
I just can't see it so hope someone else can. The error is thrown in the line containing 'areasqft=areasqft ..... and says numberformat exception. could it be the typing of the variables? Sorry to be such a pest. Thanks for all of your support.
Jim Schuchert
code from b4ppc
B4X:
Sub btnAreaOK_Click
points=txtareapoints.Text
pts()=StrSplit(points,"-") [color=red]this is b4ppc code[/color]
x=ArrayLen(pts())
'Msgbox(x)
lastpoint=pts(x-1)
firstpoint=pts(0)
lastpoint=pts(x-1)
'test for first and last points being the same
If lastpoint <>firstpoint Then '99 Then
Msgbox ("The last point must match first point")
Goto areaend
End If
'It is from here down that is important
j=0 'first point in line of numbers
FileOpen(c,strfilename,cRead)
lineoftext=FileRead(c)
Do Until lineoftext=EOF
coord()=StrSplit(lineoftext,",")
If coord(0)=pts(j) Then 'first point in line of numbers
dblnorth=coord(1)
dbleast=coord(2)
Exit
End If
lineoftext=FileRead(c)
Loop
'FileClose(c)
For i=1 To x-1
'If i>x Then Exit
FileClose(c)
FileOpen(c,strfilename,cRead)
lineoftext=FileRead(c)
Do Until lineoftext=EOF
coord()=StrSplit(lineoftext,",")
skipnextline:
If coord(0)=pts(i) Then
dblnortha=coord(1)
dbleasta=coord(2)
Areasqft = Areasqft + (dblNorth * dbleasta - dblnortha * dblEast)
dblnorth=dblnortha
dbleast=dbleasta
Exit
End If
lineoftext=FileRead(c)
Loop
Next
FileClose(c)
'b4a code
B4X:
Sub btnOK_click
'find # of points used for area calc
Dim x,areasqft,pts(),j,firstpt,points,ptnum
Dim numpts,num(),total1,total2
x=0
points="9,7,3,4,2,8,0,"
num=Regex.Split(",",points)
For i=0 To 20
ptnum=num(i)
x=x+1
If ptnum="0" Then
Exit
End If
Next
numpts=x-1
'here is where the comparison should begin
'get coord of first point in line of numbers
j=0 'first point in line of numbers
Dim cline()
Dim reader As TextReader
reader.Initialize (File.openinput(File.DirInternal,main.strfilename ))
Dim lineoftext As String
lineoftext=reader.ReadLine ' get the first line
Do While lineoftext<>Null
cline=Regex.Split(",",lineoftext)'added this here
If cline(0)=num(j) Then
main.dblnorth=cline(1)
main.dbleast=cline(2)
Exit
End If
lineoftext=reader.ReadLine ' get next line - this is tested for Null on next loop
Loop
reader.Close
'get remainder of coordinates for points
For i=1 To x-1
reader.Close
reader.Initialize (File.openinput(File.DirInternal,main.strfilename ))
lineoftext=reader.ReadLine
Do Until lineoftext=Null 'also tried do while lineoftext<>null
cline=Regex.Split(",",lineoftext)
If cline(0)=num(i) Then
main.dblnortha=cline(1)
main.dbleasta=cline(2)
Areasqft = Areasqft + (main.dblNorth * main.dbleasta) - (main.dblnortha * main.dblEast) [color=red] error is 'numberformat exception [/color]
main.dblnorth=main.dblnortha
main.dbleast=main.dbleasta
End If
lineoftext=reader.ReadLine
Loop
Next
reader.close
areasqft=areasqft/2 'sets area for all tangents
txtresults.text=txtresults.text & areasqft
End Sub
I just can't see it so hope someone else can. The error is thrown in the line containing 'areasqft=areasqft ..... and says numberformat exception. could it be the typing of the variables? Sorry to be such a pest. Thanks for all of your support.
Jim Schuchert