Tuesday, March 27, 2012

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!

DATAFILE=Text.Append(Program.Directory,"\SimpleData.csv")
'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.ReadContents(DATAFILE)

LoadCSV_r=1
LoadCSV_c=1
LoadCSV_mode=1
'rem="1=NUMBER, 2=TEXT,3=ESCAPE"
For LoadCSV_i=1 To Text.GetLength(LoadCSV_TEXTDATA)
'TextWindow.Write(Text.GetSubText(LoadCSV_TEXTDATA,LoadCSV_i,1))
LoadCSV_a=Text.GetCharacterCode(Text.GetSubText(LoadCSV_TEXTDATA,LoadCSV_i,1))
if (LoadCSV_mode=3) then
ADATA[LoadCSV_r][LoadCSV_c]=Text.Append(ADATA[LoadCSV_r][LoadCSV_c],text.GetCharacter(LoadCSV_a))
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]=Text.Append(ADATA[LoadCSV_r][LoadCSV_c],text.GetCharacter(LoadCSV_a))
ElseIf (LoadCSV_a=44) then 'comma
TextWindow.Write(text.Append(ADATA[LoadCSV_r][LoadCSV_c]," "))
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]=Text.Append(ADATA[LoadCSV_r][LoadCSV_c],text.GetCharacter(LoadCSV_a))
Else
'skip this char
EndIf
EndFor
maxr=LoadCSV_r-1
EndSub

Tuesday, March 20, 2012

SmallBasic String to Number conversion

It turns out that I don't need to do this as MS SmallBasic keeps everything in string. So, you don't need to mess with it.

Sub AtoI
'tstring - string containing number
istring=0
isign=1
iperiod=0

For s=1 To Text.GetLength(tstring)
iindex=Text.GetIndexOf(tempNum,Text.GetSubText(tstring,s,1))
If iindex=0 Then
istring=0
s=Text.GetLength(tstring+1)
ElseIf iindex=1 then
isign=-1
elseif iindex=2 then
iperiod=1
Else
istring=(istring*10)+(iindex-3)
iperiod=iperiod*10
EndIf
EndFor
istring=(istring/iperiod)*isign
EndSub

Thursday, March 15, 2012

What's new?

It's been awhile since I posted here, hasn't it? Well, I have been busy. But now things are coming around. I'll be posting with more frequency. Some programming, some Nintendo stuff. Maybe some pics and videos. Stay tuned!