Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("Layout")
wait for (DownloadFile) complete (success As Boolean)
If (success) Then
leer
End If
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub DownloadFile() As ResumableSub
'download csv file
Dim j As HttpJob
j.Initialize("", Me)
j.Download("https://docs.google.com/spreadsheets/d/1ZXx9s0yrOPZhX3GtlQgtcG7gvP6nqT74eJqiEv5H2qo/export?format=csv")
Wait For (j) JobDone(j As HttpJob)
Dim SuccessFlag As Boolean = j.Success
Log(SuccessFlag)
If SuccessFlag Then
'''Log(j.GetString)
Dim out As OutputStream = File.OpenOutput(File.DirInternal, "datos.csv", False)
File.Copy2(j.GetInputStream, out)
out.Close '<------ very important
End If
j.Release
Return SuccessFlag
End Sub
Sub leer
Log("=======LEER =====")
Dim Reader As TextReader
Dim S As String
Reader.Initialize(File.OpenInput(File.DirInternal, "datos.csv"))
S = Reader.ReadAll
Reader.Close
Log("===========")
'''Log(S)
'there are three commonly-used line separators: CR, LF, and CR+LF
'these two .Replaces will standardise S to use LF as the line separator
'LF is ASCII 10d = Chr(10); CR is ASCII 13d = Chr(13)
S = S.Replace(Chr(13) & Chr(10), Chr(10))
S = S.Replace(Chr(13), Chr(10))
Dim L() As String = Regex.Split("\n", S) 'split into lines (around line separator \n = Chr(10))
Dim NumLines As Int = L.Length
Log("NumLines = " & NumLines)
For I = 0 To NumLines - 1
Dim F() As String = Regex.Split(",", L(I)) 'split into fields (around field separator ",")
Dim NumFields As Int = F.Length
Log("NumFields = " & NumFields)
For J = 0 To NumFields - 1
Log("L(" & I & ") F(" & J & ") = """ & F(J) & """")
If J = 0 Then
Dim Ordinal() As String = Array As String("First", "Second", "Third", "Fourth")
Dim P() As String = Regex.Split(" y ", F(0))
For K = 0 To P.Length - 1 'Fortran Forever ?
Log(Ordinal(K) & " player is """ & P(K) & """")
Next
End If
Next
Next
End Sub