Microsoft Small Basic

Program Listing: XBN027
' Cash Denomination Calculator
' Version 0.1.0
' Copyright © 2020 Nonki Takahashi. The MIT License.
' Last update 2020-08-08

GraphicsWindow.Title = "Cash Denomination Calculator 0.1.0"
InitUSD()
Form()
While "True"
If buttonClicked Then
ClearCashDenomination()
amount = Controls.GetTextBoxText(tbox)
CalcCashDenomination()
ShowCashDenomination()
buttonClicked = "False"
Else
Program.Delay(200)
EndIf
EndWhile

Sub CalcCashDenomination
' param amount - of money
count = ""
i = 1
While 0 < amount
If denomi[i]["amount"] <= amount Then
count[i] = count[i] + 1
amount = amount - denomi[i]["amount"]
Else
i = i + 1
EndIf
EndWhile
EndSub

Sub ClearCashDenomination
While 0 < nShapes
Shapes.Remove(shp[nShapes])
nShapes = nShapes - 1
EndWhile
EndSub

Sub Form
gw = 600
gh = 400
GraphicsWindow.Width = gw
GraphicsWindow.Height = gh
GraphicsWindow.BrushColor = "Black"
GraphicsWindow.DrawText(10, 14, currency)
tbox = Controls.AddTextBox(50, 10)
btn = Controls.AddButton("Calculate", 220, 8)
Controls.ButtonClicked = OnButtonClicked
EndSub

Sub InitJPY
currency = "JPY"
denomi = ""
denomi[1] = "type=bill;amount=10000;display=¥10000;"
denomi[2] = "type=bill;amount=5000;display=¥5000;"
denomi[3] = "type=bill;amount=1000;display=¥1000;"
denomi[4] = "type=coin;amount=500;display=¥500;"
denomi[5] = "type=coin;amount=100;display=¥100;"
denomi[6] = "type=coin;amount=50;display=¥50;"
denomi[7] = "type=coin;amount=10;display=¥10;"
denomi[8] = "type=coin;amount=5;display=¥5;"
denomi[9] = "type=coin;amount=1;display=¥1;"
EndSub

Sub InitUSD
currency = "USD"
denomi = ""
denomi[1] = "type=bill;amount=100;display=$100;"
denomi[2] = "type=bill;amount=50;display=$50;"
denomi[3] = "type=bill;amount=20;display=$20;"
denomi[4] = "type=bill;amount=10;display=$10;"
denomi[5] = "type=bill;amount=5;display=$5;"
denomi[6] = "type=bill;amount=1;display=$1;"
denomi[7] = "type=coin;amount=0.25;display=¢25;"
denomi[8] = "type=coin;amount=0.1;display=¢10;"
denomi[9] = "type=coin;amount=0.05;display=¢5;"
denomi[10] = "type=coin;amount=0.01;display=¢1;"
EndSub

Sub OnButtonClicked
buttonClicked = "True"
EndSub

Sub ShowCashDenomination
index = Array.GetAllIndices(count)
x = 10
y = 50
nShapes = 0
For i = 1 To Array.GetItemCount(count)
If denomi[index[i]]["type"] = "bill" Then
bill = denomi[index[i]]["display"]
n = count[index[i]]
GraphicsWindow.PenColor = "Black"
GraphicsWindow.BrushColor = "White"
nShapes = nShapes + 1
shp[nShapes] = Shapes.AddRectangle(120, 60)
Shapes.Move(shp[nShapes], x, y)
GraphicsWindow.BrushColor = "Black"
nShapes = nShapes + 1
shp[nShapes] = Shapes.AddText(bill)
Shapes.Move(shp[nShapes], x + 10, y + 22)
nShapes = nShapes + 1
shp[nShapes] = Shapes.AddText("X")
Shapes.Move(shp[nShapes], x + 130, y + 22)
nShapes = nShapes + 1
shp[nShapes] = Shapes.AddText(n)
Shapes.Move(shp[nShapes], x + 150, y + 22)
Else
coin = denomi[index[i]]["display"]
n = count[index[i]]
GraphicsWindow.PenColor = "Black"
GraphicsWindow.BrushColor = "Silver"
nShapes = nShapes + 1
shp[nShapes] = Shapes.AddEllipse(60, 60)
Shapes.Move(shp[nShapes], x, y)
GraphicsWindow.BrushColor = "Black"
nShapes = nShapes + 1
shp[nShapes] = Shapes.AddText(coin)
Shapes.Move(shp[nShapes], x + 10, y + 22)
nShapes = nShapes + 1
shp[nShapes] = Shapes.AddText("X")
Shapes.Move(shp[nShapes], x + 70, y + 22)
nShapes = nShapes + 1
shp[nShapes] = Shapes.AddText(n)
Shapes.Move(shp[nShapes], x + 90, y + 22)
EndIf
y = y + 70
If gh < y + 70 Then
y = 50
x = x + 200
EndIf
EndFor
EndSub