Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ICsv - GetRowMS - and multistring
#1
I'm having trouble clearing errors on GetRowMS.

Scenario: I want to reading a csv file into icsv1 then process each line, throwing some away, modifying others.

I want to use GetRowMS to fetch a row from icsv1, muck it about, and add it to icsv2. Basically I'd rather write it this way rather that keep adjusting my tracking index on icsv1. A lazy "for" loop on icvs1 looping through all the rows.

???? marks where I need help.
Code:
Copy      Help
ICsv icsv1=CreateCsv()
icsv1.Separator=","
icsv1.FromFile("C:\testdata.txt")

int nr=sFileBuffer.RowCount
int nc=sFileBuffer.ColumnCount

ICsv icsv2=CreateCsv()
icsv2.Separator=","

???? declaration for multistring transfer row holder. Real variable decl WITHOUT using magical _s ????

int r c
for r 0 nr
    ;;.......
    icsv1.GetRowMS(r ????multistring????)
    ;;.......
    icsv2.AddRowMS(-1 nc ????multistring????)
    ;;.......

Thanks,
-dana
#2
Macro ICsv row str
Code:
Copy      Help
ICsv icsv1=CreateCsv(1)
str s1=
;a1,b1,c1
;a2,b2,c2
;a3,b3,c3
icsv1.FromString(s1)

int nr=icsv1.RowCount
int nc=icsv1.ColumnCount

ICsv icsv2=CreateCsv(1)

;???? declaration for multistring transfer row holder. Real variable decl WITHOUT using magical _s ????
str ms

int r c
for r 0 nr
,;;.......
,icsv1.GetRowMS(r ms)
,;;.......
,icsv2.AddRowMS(-1 nc ms)
,;;.......

;results
str s2; icsv2.ToString(s2); out s2

Reading/writing in multistring format is fast. But multistring format in most cases is inconvenient if you want to do something more with row data (read/change cells). Because all row cells are in single variable, and would need to parse it.

Here is example with array as a row holder.
Macro ICsv row ARRAY
Code:
Copy      Help
ICsv icsv1=CreateCsv(1)
str s1=
;a1,b1,c1
;a2,b2,c2
;a3,b3,c3
icsv1.FromString(s1)

int nr=icsv1.RowCount
int nc=icsv1.ColumnCount

ICsv icsv2=CreateCsv(1)

;???? declaration for multistring transfer row holder. Real variable decl WITHOUT using magical _s ????
ARRAY(str) a.create(nc)

int r c
for r 0 nr
,;;.......
,for(c 0 nc) a[c]=icsv1.Cell(r c)
,;;.......
,icsv2.AddRowSA(-1 nc &a[0])
,;;.......

;results
str s2; icsv2.ToString(s2); out s2
#3
THANKS!

That's very helpful though now I can't find out what I was doing that was different. You know, sometimes you just can't see into the code after you've been starring at it long enough. Looking at your example has cleared up things in my mind and I can see my path forward.

-dana
Big Grin


Forum Jump:


Users browsing this thread: 1 Guest(s)