Microsoft Small Basic

Program Listing: QXW739
' The following line could be harmful and has been automatically commented.
' setting = File.GetSettingsFilePath()
' The following line could be harmful and has been automatically commented.
' todo = File.ReadContents(setting)
continue = "True"
While continue
index = Array.GetAllIndices(todo)
num = Array.GetItemCount(todo)
For i = 1 To num
TextWindow.WriteLine(i + " " + todo[index[i]])
EndFor
TextWindow.WriteLine("")
TextWindow.Write("? ")
cmd = Text.ConvertToLowerCase(TextWindow.Read())
If cmd = "a" Then
AddTODO()
ElseIf Text.StartsWith(cmd, "d") Then
DeleteTODO()
ElseIf cmd = "q" Then
continue = "False"
Else
ShowHelp()
EndIf
EndWhile
' The following line could be harmful and has been automatically commented.
' File.WriteContents(setting, todo)
Sub AddTODO
TextWindow.Write("TODO? ")
title = TextWindow.Read()
TextWindow.Write("Due date(yyyy-mm-dd)? ")
until = TextWindow.Read()
line = ""
line["TODO"] = title
line["until"] = until
TextWindow.WriteLine(line)
MakeID()
While Array.ContainsIndex(todo, id)
MakeID()
EndWhile
todo[id] = line
EndSub
Sub DeleteTODO
n = Text.GetSubTextToEnd(cmd, 2)
If 1 <= n And n <= num Then
todo[index[n]] = ""
EndIf
EndSub
Sub MakeID
i = Math.GetRandomNumber(20)
id = Text.GetSubText("BCDFGHJKLMNPQRSTVWXZ", i, 1)
For i = 1 To 3
id = id + (Math.GetRandomNumber(10) - 1)
EndFor
EndSub
Sub ShowHelp
TextWindow.WriteLine("a : add TODO")
TextWindow.WriteLine("d : delete TODO ")
TextWindow.WriteLine("h : show this help")
TextWindow.WriteLine("q : save and exit")
EndSub