Microsoft Small Basic

Program Listing: LVG886
' Truth Table 0.1
' Copyright (c) 2013 Nonki Takahashi. All rights reserved.
'
' History:
' 0.1 2013-09-27 Created.
Init()
x0 = 10
y0 = 10
DrawNot()
y0 = y0 + 10 + dy * 3
op = "And"
DrawBinaryOp()
y0 = y0 + 10 + dy * 5
op = "Or"
DrawBinaryOp()
y0 = y0 + 10 + dy * 5
op = "Xor"
DrawBinaryOp()
Sub Init
GraphicsWindow.Title = "Truth Table 0.1"
Not = "True=False;False=True;"
Xor["True"] = "True=False;False=True;"
Xor["False"] = "True=True;False=False;"
dx = 80
dy = 20
ox = 10
oy = 2
GraphicsWindow.PenWidth = 1
GraphicsWindow.PenColor = "DimGray"
GraphicsWindow.BrushColor = "Black"
EndSub
Sub DrawNot
head = "1=p;2=Not p;"
p = "1=True;2=False;"
x1 = x0 + dx * 2
y1 = y0 + dy * 3
For i = 1 To 3
x = x0 + (i - 1) * dx
GraphicsWindow.DrawLine(x, y0, x, y1)
If i <= 2 Then
GraphicsWindow.DrawText(x + ox, y0 + oy, head[i])
EndIf
EndFor
For i = 1 To 4
y = y0 + (i - 1) * dy
GraphicsWindow.DrawLine(x0, y, x1, y)
If i <= 2 Then
GraphicsWindow.DrawText(x0 + ox, y + dy + oy, p[i])
GraphicsWindow.DrawText(x0 + dx + ox, y + dy + oy, Not[p[i]])
EndIf
EndFor
EndSub
Sub DrawBinaryOp
head = "1=p;2=q;3=p " + op + " q;"
p = "1=True;2=True;3=False;4=False;"
q = "1=True;2=False;3=True;4=False;"
x1 = x0 + dx * 3
y1 = y0 + dy * 5
For i = 1 To 4
x = x0 + (i - 1) * dx
GraphicsWindow.DrawLine(x, y0, x, y1)
If i <= 3 Then
GraphicsWindow.DrawText(x + ox, y0 + oy, head[i])
EndIf
EndFor
For i = 1 To 6
y = y0 + (i - 1) * dy
GraphicsWindow.DrawLine(x0, y, x1, y)
If i <= 4 Then
GraphicsWindow.DrawText(x0 + ox, y + dy + oy, p[i])
GraphicsWindow.DrawText(x0 + dx + ox, y + dy + oy, q[i])
BinaryOp()
GraphicsWindow.DrawText(x0 + 2 * dx + 10, y + dy + 1, r)
EndIf
EndFor
EndSub
Sub BinaryOp
If op = "And" Then
If p[i] And q[i] Then
r = "True"
Else
r = "False"
EndIf
ElseIf op = "Or" Then
If p[i] Or q[i] Then
r = "True"
Else
r = "False"
EndIf
ElseIf op = "Xor" Then
r = Xor[p[i]][q[i]]
EndIf
EndSub