I want to use this data to create a pdf page. Code as follows:
B4X:
Dim redc As List
redc.Initialize
Dim rs As ResultSet=sql.ExecQuery $" Select * from current "$
Dim cre(3) As Object
Do While rs.NextRow
cre(0) =rs.Getstring("red")
cre(1)=rs.Getstring("green")
cre(2)=rs.Getstring("blue")
redc.Addall(Array As String(""&cre(0),""&cre(1),""&cre(2)))
Loop
rs.Close
File.Writelist (File.DirInternal, "mylist.txt", redc)
I think the reason it is noty working as expected is that you need some Carridge returns in the output.
Reading the definition of Write List the easiest way to do this would be to change the code as follows:
B4X:
Dim redc As List
redc.Initialize
Dim rs As ResultSet=sql.ExecQuery $" Select * from current "$
Do While rs.NextRow
' Add a CRLF after every set of values.
redc.Addall(Array As String(rs.getstring("red"),rs.getstring("green"),rs.getstring("blue"), CRLF))
Loop
rs.Close
File.Writelist (File.DirInternal, "mylist.txt", redc)
BTW, is there a reason you cast the result from a string to an object to a string again?
Without fully understanding exactly what you are doing, you could remove the need for an external textfile completely.
B4X:
dim outputstr as string = ""
Dim rs As ResultSet=sql.ExecQuery $" Select * from current "$
Do While rs.NextRow
' Add a CRLF after every set of values.
outputstr = outputstr & $"${rs.getstring("red")},${rs.getstring("green")},${rs.getstring("blue")}${CRLF}"$
Loop
rs.Close
pdf.Canvas.DrawText(outputstr, 250, 150, Typeface.DEFAULT_BOLD, 30 / GetDeviceLayoutValues.Scale , Colors.blue, "CENTER")
or it could be that you write each line separately.
as far as the spaces go I would have expected that these would have been Carriage returns.
Perhaps the solution is to put the drawtext within the loop.
something such as:
B4X:
dim outputstr as string = ""
dim yoff as float = 0
Dim rs As ResultSet=sql.ExecQuery $" Select * from current "$
Do While rs.NextRow
' Add a CRLF after every set of values.
outputstr = $"${rs.getstring("red")} ${rs.getstring("green")} ${rs.getstring("blue")}"$
pdf.Canvas.DrawText(outputstr, 250, 150+ yoff, Typeface.DEFAULT_BOLD, 30 / GetDeviceLayoutValues.Scale , Colors.blue, "CENTER")
yoff = yoff + pdf.Canvas.MeasureStringHeight(outputstr, Typeface.DEFAULT_BOLD, 30 / GetDeviceLayoutValues.Scale)
Loop
rs.Close
Canvas.DrawText ignores the CRLF character and replaces it by an empty character. DrawText("Test text" and DrawText("Test" & CRLF & "text" give the same result.
You need to write each line in a loop and change the Y coordinate for each line.
as far as the spaces go I would have expected that these would have been Carriage returns.
Perhaps the solution is to put the drawtext within the loop.
something such as:
B4X:
dim outputstr as string = ""
dim yoff as float = 0
Dim rs As ResultSet=sql.ExecQuery $" Select * from current "$
Do While rs.NextRow
' Add a CRLF after every set of values.
outputstr = $"${rs.getstring("red")} ${rs.getstring("green")} ${rs.getstring("blue")}"$
pdf.Canvas.DrawText(outputstr, 250, 150+ yoff, Typeface.DEFAULT_BOLD, 30 / GetDeviceLayoutValues.Scale , Colors.blue, "CENTER")
yoff = yoff + pdf.Canvas.MeasureStringHeight(outputstr, Typeface.DEFAULT_BOLD, 30 / GetDeviceLayoutValues.Scale)
Loop
rs.Close