Microsoft Small Basic

Program Listing: HMK932-0
' Program Database 0.2a
' Copyright (c) 2014 Nonki Takahashi. MIT License.
'
' History:
' 0.2a 2014-06-24 Design changed. (HMK932-0)
' 0.1a 2014-06-09 Created. (HMK932)
'
GraphicsWindow.Title = "Program Database 0.2a"
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()
y = 10
Controls_Init()
For i = 1 To 3
x = 10
If 1 < i Then
item = "1=AND;2=OR;"
left = x
top = y
Controls_AddComboBox()
cbLOp[i] = cbox
EndIf
x = x + 80
item = hd
left = x
top = y
Controls_AddComboBox()
cbItem[i] = cbox
x = x + 190
item = "1=\=;2=>;3=<;4=>\=;5=<\=;6=<>;7=LIKE;"
left = x
top = y
Controls_AddComboBox()
x = x + 80
cbOp[i] = cbox
tb[i] = Controls.AddTextBox(x, y)
Controls.SetSize(tb[i], gw - 10 - x, 22)
y = y + 30
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)
While "True"
If Controls_triggered Then
Controls_Proc()
Else
Program.Delay(200)
EndIf
EndWhile
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
Sub Controls_AddComboBox
' param item - array of items
' param left - the x co-ordinate of the combo box
' param top - the y co-ordinate of the combo box
' return cbox - the combo box
' version 0.11a
Stack.PushValue("local", i)
nCBox = nCBox + 1
fs = GraphicsWindow.FontSize
cbProp[nCBox]["is"] = fs * 1.4
nItem = Array.GetItemCount(item)
cbProp[nCBox]["nItem"] = nItem
cbProp[nCBox]["item"] = item
widthMax = 0
For i = 1 To nItem
len = Text.GetLength(item[i])
width = 0
For j = 1 To len
width = width + Math.Floor(luw[Text.GetSubText(item[i], j, 1)] * fs / 100)
EndFor
If widthMax < width Then
widthMax = width
EndIf
EndFor
tboxWidth = widthMax + fs
cbProp[nCBox]["menuWidth"] = tboxWidth
cbProp[nCBox]["menuX"] = left
cbProp[nCBox]["menuY"] = top
cbProp[nCBox]["tbox"] = Controls.AddTextBox(left, top)
Controls.SetSize(cbProp[nCBox]["tbox"], tboxWidth, fs * 1.8)
cbProp[nCBox]["btn"] = Controls.AddButton("▾", left + tboxWidth, top)
Controls.SetSize(cbProp[nCBox]["btn"], fs * 2, fs * 1.8)
cbox = "ComboBox" + nCBox
Controls.ButtonClicked = Controls_OnButtonClicked
i = Stack.PopValue("local")
EndSub
Sub Controls_Proc
' version 0.1a
For i = 1 To nCBox
If Controls.LastClickedButton = cbProp[i]["btn"] Then
GraphicsWindow.PenColor = "LightGray"
GraphicsWindow.PenWidth = 1
GraphicsWindow.BrushColor = "White"
rect = Shapes.AddRectangle(cbProp[i]["menuWidth"], cbProp[i]["is"] * cbProp[i]["nItem"])
Shapes.Move(rect, cbProp[i]["menuX"], cbProp[i]["menuY"])
GraphicsWindow.BrushColor = "Black"
For j = 1 To cbProp[i]["nItem"]
it[j] = Shapes.AddText(cbProp[i]["item"][j])
Shapes.Move(it[j], cbProp[i]["menuX"] + cbProp[i]["is"] / 2, cbProp[i]["menuY"] + (j - 1) * cbProp[i]["is"])
EndFor
Program.Delay(1000)
For j = 1 To cbProp[i]["nItem"]
Shapes.Remove(it[j])
EndFor
Shapes.Remove(rect)
Controls.SetTextBoxText(cbProp[i]["tbox"],cbProp[i]["item"][Math.GetRandomNumber(cbProp[i]["nItem"])])
EndIf
EndFor
Controls_triggered = "False"
EndSub
Sub Controls_Init
' version 0.1a
GraphicsWindow.FontName = "Lucida UI"
GraphicsWindow.BrushColor = "Black"
WQ = Text.GetCharacter(34)
' Lucida UI font width [px] table while the size (height) 100 [px]
luw = " =60;!=65;" + WQ + "=82;#=92;$=90;%=119;&=117;'=62;(=69;)=69;"
luw = luw + "*=78;+=103;,=59;-=73;.=59;/=77;0=90;1=90;2=90;3=90;4=90;"
luw = luw + "5=90;6=90;7=90;8=90;9=90;:=59;\;=59;<=103;\==103;>=103;"
luw = luw + "?=76;@=128;A=86;B=94;C=80;D=94;E=86;F=71;G=94;H=93;I=61;"
luw = luw + "J=61;K=88;L=61;M=124;N=93;O=94;P=94;Q=94;R=72;S=76;T=71;"
luw = luw + "U=93;V=87;W=112;X=88;Y=86;Z=80;[=69;\\=76;]=69;^=103;_=74;"
luw = luw + "`=64;{=69;|=65;}=69;~=103; =60;¡=65;¢=90;£=90;¤=88;¥=90;"
luw = luw + "¦=65;§=81;¨=79;©=120;ª=73;«=90;¬=103;­=32;®=120;¯=74;°=70;"
luw = luw + "±=103;²=73;³=73;´=63;µ=94;¶=83;·=59;¸=54;¹=72;º=78;»=90;"
luw = luw + "¼=128;½=129;¾=130;¿=76;À=86;Á=86;Â=86;Ã=86;Ä=86;Å=86;Æ=115;"
luw = luw + "Ç=80;È=86;É=86;Ê=86;Ë=86;Ì=61;Í=61;Î=61;Ï=61;Ð=92;Ñ=93;Ò=93;"
luw = luw + "Ó=93;Ô=93;Õ=93;Ö=93;×=103;Ø=94;Ù=93;Ú=93;Û=93;Ü=93;Ý=86;"
luw = luw + "Þ=94;ß=95;÷=103;ÿ=86;"
Controls_triggered = "False"
EndSub
Sub Controls_OnButtonClicked
' version 0.1a
Controls_triggered = "True"
EndSub