This has been tested using Yahoo Finance download data and Microsoft Works spreadsheet export "save as cvs". It is very useful to be able to load data for analysis. Basically, loading data is crucial to any worthwhile program, and comma separated values are pretty standard. Please feel free to modify to suit, and please give me feedback!
'TextWindow.writeline(DATAFILE
LoadCSV()
For r=1 To maxr
For c=1 To maxc
TextWindow.Write(ADATA[r][c])
TextWindow.Write("\t")
EndFor
TextWindow.Writeline("\n")
EndFor
TextWindow.Pause()
Program.End()
Sub LoadCSV
'DATAFILE = Filename of CSV file (input)
'ADATA[r][c] = Array of CSV data (output)
'maxr,maxc = max row, max col (output)
LoadCSV_TEXTDATA=File.ReadCont
LoadCSV_r=1
LoadCSV_c=1
LoadCSV_mode=1
'rem="1=NUMBER, 2=TEXT,3=ESCAPE"
For LoadCSV_i=1 To Text.GetLength(LoadCSV_TEXTDAT
'TextWindow.Write(Text.GetSubT
LoadCSV_a=Text.GetCharacterCod
if (LoadCSV_mode=3) then
ADATA[LoadCSV_r][LoadCSV_c]=Te
LoadCSV_mode=2
elseif (LoadCSV_a=92 and LoadCSV_mode=2) Then '\ escape
LoadCSV_mode=3
ElseIf (LoadCSV_a=34) Then 'quote
LoadCSV_mode=3-LoadCSV_mode
elseif (LoadCSV_mode=2) then
ADATA[LoadCSV_r][LoadCSV_c]=Te
ElseIf (LoadCSV_a=44) then 'comma
TextWindow.Write(text.Append(A
LoadCSV_c=LoadCSV_c+1
elseif (LoadCSV_a=10) then 'newline
LoadCSV_r=LoadCSV_r+1
maxc=LoadCSV_c-1
LoadCSV_c=1
TextWindow.WriteLine(" ")
elseif (LoadCSV_a>=32) then 'text
ADATA[LoadCSV_r][LoadCSV_c]=Te
Else
'skip this char
EndIf
EndFor
maxr=LoadCSV_r-1
EndSub
No comments:
Post a Comment