Hi,
i download some information from web server in this format
First 4 char are a code
From 6 char to ; is a description
After ; is a value
For extract data from downloaded information i use this code:
When i run this code alla works fine but variable promozione obtained from line 513 (Main)
shows this error
Code is able to show only, if present, first number in line (like in '2008 10example data - (example) - data;200' )
If line starts with string (like in '2014 example data - (example) - data 2;2000) the the previous error is shown
So i think that my error is in any variable definition or in some error in conversion in another type of variable
I've tried everything but can't figure out where is the error
Any help is welcome
Thank you
i download some information from web server in this format
2008 10example data - (example) - data;200
2014 example data - (example) - data 2;2000
First 4 char are a code
From 6 char to ; is a description
After ; is a value
For extract data from downloaded information i use this code:
B4X:
Private Sub promozioni_Click
mostraofferte1.Initialize("mostraofferte")
mostraofferte1.RootPanel.LoadLayout("mostraofferte")
mostraofferte1.Title="Ciao " & nomeutente & " hai " & totpunti & " punti"
Dim linea As String
Dim dove As Int
Dim xui As XUI
Dim codice As String
Dim punti As String
Dim i As Int
LstPromozioni.Clear
NavControl.ShowPage(mostraofferte1)
Try
Dim j As HttpJob
j.Initialize("j", Me)
j.Download("https://myserver.web/showdata.asp")
Wait For (j) JobDone(j As HttpJob)
'Sleep(500)
If j.Success Then
If j.GetString<>"KO" Then
Dim out As OutputStream = File.OpenOutput(File.DirDocuments, "promozioni.txt", False)
File.Copy2(j.GetInputStream, out)
out.close
''File.WriteString(File.DirDocuments,"promozioni.txt",j.GetString)
mylist=File.ReadList(File.DirDocuments,"promozioni.txt")
i=0
If mylist.size>1 Then
For i= 0 To mylist.Size-1
linea=mylist.Get(i)
dove=linea.IndexOf(";")
codice=linea.SubString2(0,4)
promozione=linea.SubString2(5,dove)
punti=linea.SubString(dove+1)
If i Mod 2 =0 Then
LstPromozioni.DefaultTextBackgroundColor=Colors.RGB(0,128,0)
LstPromozioni.DefaultTextColor=Colors.White
Else
LstPromozioni.DefaultTextBackgroundColor=Colors.white
LstPromozioni.DefaultTextColor=Colors.Black
End If
Log(promozione&CRLF&punti)
LstPromozioni.AddTextItem(promozione&CRLF&punti,codice)
Next
End If
End If
End If
j.Release
Catch
Log(LastException.Message)
End Try
End Sub
When i run this code alla works fine but variable promozione obtained from line 513 (Main)
B4X:
promozione=linea.SubString2(5,dove)
shows this error
Class (b4i_httpjob) instance released.
Class (b4i_customlistview) instance released.
Class (b4i_httpjob) instance released.
10
Error occurred on line: 513 (Main)
Cannot parse: example data - (example) - data 2
Stack Trace: (
CoreFoundation 14B73572-A1BC-3C77-A58A-A64A28663D46 + 38040
libobjc.A.dylib objc_exception_throw + 56
CoreFoundation 14B73572-A1BC-3C77-A58A-A64A28663D46 + 964464
ReversApp -[B4I ObjectToNumber:] + 336
ReversApp -[B4IRDebugUtils numberCast::] + 260
CoreFoundation 14B73572-A1BC-3C77-A58A-A64A28663D46 + 450496
CoreFoundation 14B73572-A1BC-3C77-A58A-A64A28663D46 + 127560
ReversApp +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1296
ReversApp -[B4IShell runMethod:] + 420
ReversApp -[B4IShell raiseEventImpl:method:args::] + 1472
ReversApp -[B4IShellBI raiseEvent:eventarams:] + 1360
ReversApp -[B4IDebugResumableSub resume::] + 352
ReversApp -[B4I checkAndRunWaitForEvent:eventarams:] + 440
ReversApp -[B4IShellBI raiseEvent:eventarams:] + 1216
ReversApp -[B4ICommon CallSub4::::] + 240
ReversApp -[B4ICommon CallSub2::::] + 272
ReversApp -[b4i_httpjob _complete::] + 620
ReversApp -[b4i_httputils2service _completejob::::] + 1276
ReversApp -[b4i_httputils2service _hc_responsesuccess::] + 452
CoreFoundation 14B73572-A1BC-3C77-A58A-A64A28663D46 + 450496
CoreFoundation 14B73572-A1BC-3C77-A58A-A64A28663D46 + 127560
ReversApp +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1296
ReversApp -[B4IShell runMethod:] + 420
ReversApp -[B4IShell raiseEventImpl:method:args::] + 1968
ReversApp -[B4IShellBI raiseEvent:eventarams:] + 1360
ReversApp __61-[B4IHttp URLSession:downloadTask:didFinishDownloadingToURL:]_block_invoke + 308
libdispatch.dylib A893D1C3-FCC0-3FBA-8AED-CBDC8C4C37CE + 411520
libdispatch.dylib A893D1C3-FCC0-3FBA-8AED-CBDC8C4C37CE + 289572
libdispatch.dylib A893D1C3-FCC0-3FBA-8AED-CBDC8C4C37CE + 411520
libdispatch.dylib A893D1C3-FCC0-3FBA-8AED-CBDC8C4C37CE + 286224
libdispatch.dylib A893D1C3-FCC0-3FBA-8AED-CBDC8C4C37CE + 285320
CoreFoundation 14B73572-A1BC-3C77-A58A-A64A28663D46 + 596524
CoreFoundation 14B73572-A1BC-3C77-A58A-A64A28663D46 + 480968
CoreFoundation CFRunLoopRunSpecific + 584
GraphicsServices GSEventRunModal + 160
UIKitCore DF57BFBD-C5E1-38E0-9009-CA7394D39A34 + 3608536
UIKitCore UIApplicationMain + 312
ReversApp main + 100
dyld DA5F527D-AD76-324B-AB9C-254FC806F191 + 82756
)
Cannot parse: example data - (example) - data 2
Code is able to show only, if present, first number in line (like in '2008 10example data - (example) - data;200' )
If line starts with string (like in '2014 example data - (example) - data 2;2000) the the previous error is shown
So i think that my error is in any variable definition or in some error in conversion in another type of variable
I've tried everything but can't figure out where is the error
Any help is welcome
Thank you