Output ListIconGadget to .csv
Posted: Sun Mar 16, 2008 12:22 am
Here is the procedure I use to output a ListIconGadget() to a .csv file.
Documenting now... NOW commented version... 
Code: Select all
Procedure ExporttoCSV()
;*
yy$ = FormatDate("%yy%mm%dd",Date()) ; I use this for the output filename
by$ = GetGadgetText(#Text_REPORT) ; this variable holds my report name portion - point to your name for this file
FileName$ = yy$+by$+".csv" ; add those two variables and add a .csv for comma saved
StandardFile$ = "C:\My Documents\"+Filename$+"" ; set initial file+path to display in filerequester
Pattern$ = "CSV (*.csv)|*.csv|Text (*.txt)|*.txt|All files (*.*)|*.*"
Pattern = 0
File$ = SaveFileRequester("Please choose Where to SAVE...", StandardFile$, Pattern$, Pattern)
If File$
MessageRequester("Information", "You have saved following file:" + Chr(10) + File$, 0) ; those running unicode may have to use #CRLF (I think)
Else
MessageRequester("Information", "The requester was canceled.", 0)
EndIf
OpenFile(#File, File$) ; you will have to declare a #File
Result = CountGadgetItems(#ListIcon_BIG) ; name of my ListIcon() thingee
For cc = 0 To COLFLAG - 1
tit$ = GetGadgetItemText(#ListICon_BIG, -1,cc) ; get text of column headers
tit$ = tit$ +","
title$ = title$ + tit$
tit$ = ""
Next
WriteStringN(#File, title$) ; write the title string
title$ = ""
For lin = 0 To Result - 1 ; number of lines
For col = 0 To COLFLAG - 1 ; number of columns
plink$ = GetGadgetItemText(#ListIcon_BIG,lin,col) ; get that LOCATION and put it in plink$
plink$ = plink$+"," ; add a comma (this is a CSV file)
plonk$ = plonk$ + plink$ ; add plink$ to plonk$
Debug "PLoNK: "+plonk$
; plink$ = "" ; kill value in plink$
If col = COLFLAG ; EOL reached
cut = Len(plonk$) - 1
plonk$ = Left(plonk$,cut) ; cut off the last ","
EndIf
Next
WriteStringN(#File, plonk$) ; write the entire plonk$
plonk$ = "" ; kill value in plonk$
Next
CloseFile(#File)
EndProcedure
