I have created several points that need to be stored in my file. However I am getting an error that states "File blah blah cannot be accessed because it is being used by another process". This said to me that the file was still open when I tried to open it again. However, I have made sure the file was closed as the following code will show. Here is the code leading up to the problem:
Then here is the code for the storecoord sub:
All of the numbers work leading up to the problem. I have successfully stored points using this sub with other routines. Could the error message be intimating something else? I suspect it might be bad logic within the For...Next with Do...until embedded but can't pinpoint it. I appreciate all the past support I have gotten here. Thanks.
Jim Schuchert
B4X:
Sub compassrule(dnorthstart,deaststart, totaldist, sfirst, spend)
erlat = main.closenorth - dblNorth 'total error in latitude
erdep = main.closeeast - dblEast 'total error in departure
FileClose(c)
FileOpen(c,main.strfilename,cRead)
lineoftext=FileRead(c)
Do Until lineoftext=EOF
coord()=StrSplit(lineoftext,",")
If coord(0)=main.strfirst Then
dblNorth1 = coord(1)
dblEast1 = coord(2)
Exit
End If
lineoftext=FileRead(c)
Loop
FileClose(c)
For i = main.strpointno-(main.intcounter) To main.strpointno-1
FileClose(c)
FileOpen(c,main.strfilename,cRead)
lineoftext=FileRead(c)
Do Until lineoftext=EOF
coord()=StrSplit(lineoftext,",")
If coord(0)=i Then
dblNorth2 = coord(1)
dblEast2 = coord(2)
dblNdiff = Abs(dblNorth1 - dblNorth2)
dblEdiff = Abs(dblEast1 - dblEast2)
dist = Sqrt(dblNdiff ^ 2 + dblEdiff ^ 2)
lat = lat + (dist * erlat / totaldist)
dep = dep + (dist * erdep / totaldist)
dblNorth2 = dblNorth2 + lat
dblEast2 = dblEast2 + dep
coord(1) = dblNorth2
coord(2) = dblEast2
coord(0) = i
dblnorth=dblnorth2
dbleast=dbleast2
main.strpointno=coord(0)
FileClose(c)
CallSub("storecoord") 'problem after this sub is called
dblNorth1 = dblNorth2
dblEast1 = dblEast2
Exit
End If
lineoftext=FileRead(c)
Loop
FileClose(c)
Next
FileClose(c)
End Sub
Then here is the code for the storecoord sub:
B4X:
Sub storecoord()
coord(0) = main.strpointno
coord(1) = dblNorth
coord(2) = dblEast
FileClose(c)
FileOpen(c,main.strfilename,cWrite,cAppend) '[color=red] Where error is triggered [/color]
FileWrite(c, coord(0) & "," & coord(1) & "," & coord(2) & "," & coord(3))
FileClose(c)
End Sub
All of the numbers work leading up to the problem. I have successfully stored points using this sub with other routines. Could the error message be intimating something else? I suspect it might be bad logic within the For...Next with Do...until embedded but can't pinpoint it. I appreciate all the past support I have gotten here. Thanks.
Jim Schuchert