Microsoft Small Basic

Program Listing: HMK932
' Program Database 0.1a
' Copyright (c) 2014 Nonki Takahashi.
'
' History:
' 0.1a 2014-06-09 Created. ()
'
GraphicsWindow.Title = "Program Database 0.1a"
CRLF = Text.GetCharacter(13) + Text.GetCharacter(10)
gw = 598
gh = 428
GraphicsWindow.Width = gw
GraphicsWindow.Height = gh
CRLF = Text.GetCharacter(13) + text.GetCharacter(10)
GraphicsWindow.BackgroundColor = "LightGray"
GraphicsWindow.BrushColor = "Black"
hd = "1=Program ID;2=Source Filename;3=Screen Shot;4=Description;5=Last Update;6=Version;7=Author;8=Lines;9=Subroutines;10=Challenge;"
filename = Program.Directory + "\ProgramDB.csv"
ReadCSV()
x = 10
y = 10
For i = 1 To 10
GraphicsWindow.DrawText(x, y + 4, Text.GetSubTextToEnd(" ", Text.GetLength(i)) + i + ". " + hd[i])
tb[i] = Controls.AddTextBox(x + 130, y)
Controls.SetSize(tb[i], 140, 22)
y = y + 30
If 5 = i Then
y = 10
x = gw / 2
EndIf
EndFor
x = 10
bt = Controls.AddButton("Search", x, y)
tx = Shapes.AddText("Records: " + num + " / " + num)
Shapes.Move(tx, gw / 2, y + 4)
y = y + 40
mtb = Controls.AddMultiLineTextBox(x, y)
Controls.SetSize(mtb, gw - 20, gh - y - 10)
buf = ""
For i = 1 To num
For j = 1 To 10
buf = buf + pgm[i][j]
If j < 10 Then
buf = Text.Append(buf, ",")
EndIf
EndFor
buf = buf + CRLF
EndFor
Controls.SetTextBoxText(mtb, buf)
Sub ReadCSV
' param filename
' return pgm
' return num
buf = "dummy"
num = 0
While buf <> ""
num = num + 1
' The following line could be harmful and has been automatically commented.
' buf = File.ReadLine(filename, num)
If buf = "" Then
num = num - 1
Else
j = 1
p = 1
c = Text.GetIndexOf(Text.GetSubTextToEnd(buf, p), ",")
While 0 < c
pgm[num][j] = Text.GetSubText(buf, p, c - 1)
p = p + c
j = j + 1
c = Text.GetIndexOf(Text.GetSubTextToEnd(buf, p), ",")
EndWhile
pgm[num][j] = Text.GetSubTextToEnd(buf, p)
EndIf
EndWhile
EndSub
Sub WriteCSV
' param filename
' param pgm
' param num
' The following line could be harmful and has been automatically commented.
' File.WriteContents(filename, "")
For i = 1 To num
n = Array.GetItemCount(pgm[i])
buf = ""
For j = 1 To n
buf = buf + pgm[i][j]
If j < n Then
buf = buf + ","
EndIf
EndFor
' The following line could be harmful and has been automatically commented.
' File.WriteLine(filename, i, buf)
EndFor
EndSub