Android Question write text to new line

apty

Active Member
Licensed User
Longtime User
I have the following code
B4X:
Sub Accelerometer_AccelerometerChanged (X As Float, Y As Float, Z As Float)
Dim Ax As Float
Dim Ay As Float
Dim Az As Float
Ax=X
Ay=Y
Az=Z
xval.Text=Ax
yval.Text=Ay
zval.Text=Az

File.WriteString(File.DirRootExternal, "myaccval.txt", xval.Text&","&yval.Text&","&zval.Text)

End Sub

the code writes only 1 line in the text file. How can i make it write accelerometer values as they are shown in the labels? i want to capture x,y,z values as they change. i have tried looping using do while but it doesn't work
 

apty

Active Member
Licensed User
Longtime User
It still writes only 1 line. Accelerometer values keep changing very fast and i want to capture all of them (save them in a textfile one after the other)
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
sure one line... The command File.writestring open(recreate) or create a file and write the text to it and close the file. There is no possibility to APPEND to this file...

B4X:
Sub WriteTextWriter
Dim TextWriter1 As TextWriter
TextWriter1.Initialize(File.OpenOutput(File.DirRootExternal, "GPS_log.txt", True))
TextWriter1.WriteLine(time1 & "," & lat & "," & lon & "," & speed)
TextWriter1.Close
End Sub
 
Last edited:
Upvote 0

apty

Active Member
Licensed User
Longtime User
i have also used the text writer but it behaves just like File.WriteString. It only writes one line
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
i have also used the text writer but it behaves just like File.WriteString. It only writes one line

WRONG!

B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    For i = 1 To 10
        WriteTextWriter("Testline "&i)
    Next
  End Sub
Sub WriteTextWriter(text As String)
	Dim TextWriter1 As TextWriter
	TextWriter1.Initialize(File.OpenOutput(File.DirRootExternal, "log.txt", True))
	TextWriter1.WriteLine(text)
	TextWriter1.Close
End Sub

Testline 1
Testline 2
Testline 3
Testline 4
Testline 5
Testline 6
Testline 7
Testline 8
Testline 9
Testline 10
 
Upvote 0
Top