LoadCSV from a variable

nsidney

Member
Licensed User
I would like to load CSV data from a webresponse variable into a ListBox, but I get the error "Object reference not set to an instance of the object." Is there a way around this?

Thanks

B4X:
Response.Value = Request.GetResponse
result = Response.GetString
Response.Close
Eventlist.loadcsv(result, ",", false, true)
 

Cableguy

Expert
Licensed User
What is the tipe of the "Response" control?
Does the getresponse statements retrieve any result?
 

nsidney

Member
Licensed User
the "result" is the result of a WebReponse function and data is actually returned successfully (I verified that with a msgBox that displays the value of "result").

thanks!
 

Cableguy

Expert
Licensed User
These are the properties and methods supported by a listbox...

Properties and Methods:
Add
BringToFront
Clear
Color
Count
Dispose
Enabled
Focus
FontColor
FontSize
Height
Insert
Item
Left
Name
Refresh
Remove
RemoveAt
SelectedIndex
Top
Visible
Width
Events:
GotFocus
SelectionChanged
LostFocus
The is no loadcsv method in a listbox, but there is one tablecontrol...
B4X:
Properties and Methods:
             AddCol
             AddRow
             BringToFront
             CaseSensitive
             Cell
             Clear
             ColCount
             ColName
             ColNumber
             Color
             ColWidth
             Dispose
             Enabled
             Filter
             Focus
             FontColor
             FontSize
             HeaderColor
             HeaderFontColor
             HeaderVisible
             Height
             Left
             LinesColor
             LoadCSV
             LoadXML
             Name
             Refresh
             RemoveCol
             RemoveRow
             RowCount
             SaveCSV
             SaveXML
             SelectCell
             SelectedCol
             SelectedRow
             TableSort
             Top
             Visible
             Width
Events:
             SelectionChanged
Wich you can read and populate the listbox...
 

nsidney

Member
Licensed User
Oops... didn't notice the difference there ;).

Ok so when I changed it into a Table control, it thinks "result" is the name of the file. How can I take "response" and feed that into a file and then send that file name to this LoadCSV function?

Thanks
 

nsidney

Member
Licensed User
Or... is there an easier way to loop through CSV data and add each row to the table (or a listbox)?
 

Cableguy

Expert
Licensed User
Were does the data came from? a file or from a web site?
If all the data cames in a simple string with a know separator you can use StrSplit

StrSplit Previous Top Next

--------------------------------------------------------------------------------
Splits a string and returns an array of strings.
Syntax: SrtSplit (RawString, Separators)
RawString - The string that will be split.
Separators - Zero or more characters that act as the separators.
If the Separators string is an empty string then all white characters will be used as the separators.
Example:
Sub Globals
dim words(0) as string
End Sub
Sub App_Start
sentence = "$GPGGA,161229.487,3723.2475,N,12158.3416,W,1,07,1.0,9.0,M,,,,0000*18"
words() = StrSplit(sentence, ",")
for i = 0 to ArrayLen(words())-1
msgbox(words(i))
next
End Sub
 

alfcen

Well-Known Member
Licensed User
Hi nsidney,

If the expected data amount in 'result' is small then please try this way:

B4X:
Response.Value = Request.GetResponse
result = Response.GetString
Response.Close

FileOpen(c1,AppPath & "\interim.csv",cWrite)
FileWrite(c1,result)
FileClose(c1)

Table1.LoadCSV(AppPath & "\interim.csv", ",", false, true)
You can then populate a listbox or a combobox from the table with the
added advantage of having a backup file of the downloaded data.
 
Top