Microsoft Small Basic

Program Listing: BQJ710
' Calc v0.1 - (C) 2011 Nonki Takahashi
'
' History
' 2010/03/06 v0.1 Graphic design completed (191 lines)
'
' Naming convention
' class Xxx_
' label lXxx
' constant XXX
' variable type integer iXxx
' variable type real rXxx
' variable type string sXxx
' variable type url uXxx
' variable type char cXxx
' variable type boolean bXxx
' variable type object oXxx
'
' Main
Body_Init()
Body_Draw()
While "True"
Button_InputKey()
Calc_EvalExp()
EndWhile
'
Sub Body_Init
VERSION = "01" ' v0.1
TYPE = "A" ' alpha version
Calc_sExp = "123456789012"
Calc_sExp = "0+1-2*3/4.56"
Calc_iAns = 0
Body_iWidth = 300
Body_iHeight = 400
Body_sFontName = "Arial"
Body_iFontSize = 14
LCD_iWX0 = 35 ' LCD window size
LCD_iWX1 = 265
LCD_iWY0 = 80
LCD_iWY1 = 130
LCD_sFontName = "Consolas"
LCD_iFontSize = 30
LCD_iEX0 = LCD_iWX0 + 15
LCD_iEY0 = LCD_iWY0 + 15
Button_iX0 = LCD_iWX0 - 20
Button_iY0 = LCD_iWY1 + 50
Button_iX1 = LCD_iWX1 + 20
Button_iY1 = LCD_iWY1 + 400
Button_iWidth = 60
Button_iHeight = 30
Button_iGX = Math.Floor(((Button_iX1 - Button_iX0) - Button_iWidth * 4) / 3)
Button_iGY = Math.Floor(((Button_iY1 - Button_iY0) - Button_iWidth * 5) / 4)
Button_idX = Button_iWidth + Button_iGX
Button_idY = Button_iHeight + Button_iGY
Button_sKey[1][1] = "AC"
Button_sKey[2][1] = "BS"
Button_sKey[3][1] = "ANS"
Button_sKey[4][1] = "/"
Button_sKey[1][2] = "7"
Button_sKey[2][2] = "8"
Button_sKey[3][2] = "9"
Button_sKey[4][2] = "*"
Button_sKey[1][3] = "4"
Button_sKey[2][3] = "5"
Button_sKey[3][3] = "6"
Button_sKey[4][3] = "-"
Button_sKey[1][4] = "1"
Button_sKey[2][4] = "2"
Button_sKey[3][4] = "3"
Button_sKey[4][4] = "+"
Button_sKey[1][5] = "0"
Button_sKey[2][5] = "."
Button_sKey[3][5] = "EXE"
Button_iX[1][1] = 14 ' "AC"
Button_iX[2][1] = 14 ' "BS"
Button_iX[3][1] = 8 ' "ANS"
Button_iX[4][1] = 22 ' "/"
Button_iX[1][2] = 18 ' "7"
Button_iX[2][2] = 18 ' "8"
Button_iX[3][2] = 18 ' "9"
Button_iX[4][2] = 20 ' "*"
Button_iX[1][3] = 18 ' "4"
Button_iX[2][3] = 18 ' "5"
Button_iX[3][3] = 18 ' "6"
Button_iX[4][3] = 21 ' "-"
Button_iX[1][4] = 18 ' "1"
Button_iX[2][4] = 18 ' "2"
Button_iX[3][4] = 18 ' "3"
Button_iX[4][4] = 18 ' "+"
Button_iX[1][5] = 18 ' "0"
Button_iX[2][5] = 20 ' "."
Button_iX[3][5] = 40 ' "EXE"
EndSub
'
Sub Body_Draw
GraphicsWindow.Width = Body_iWidth
GraphicsWindow.Height = Body_iHeight
GraphicsWindow.BrushColor = "Gainsboro" ' body color
GraphicsWindow.FillRectangle(0, 0, Body_iWidth, Body_iHeight)
GraphicsWindow.FontName = "Arial Black"
GraphicsWindow.FontSize = 20
GraphicsWindow.BrushColor = "DimGray"
GraphicsWindow.DrawText(15, 10, "NONKI")
GraphicsWindow.FontName = Body_sFontName
GraphicsWindow.FontSize = Body_iFontSize
GraphicsWindow.DrawText(15, 34, "CA-" + VERSION + TYPE)
GraphicsWindow.DrawText(220, 10, "12 DIGITS")
LCD_Draw()
Button_DrawNumKeys()
EndSub
'
Sub LCD_Draw
iWidth = LCD_iWX1 - LCD_iWX0
iHeight = LCD_iWY1 - LCD_iWY0
GraphicsWindow.BrushColor = "DimGray" ' LCD frame color
GraphicsWindow.FillRectangle(LCD_iWX0 - 20, LCD_iWY0 - 15, iWidth + 40, iHeight + 30)
GraphicsWindow.BrushColor = "DarkKhaki" ' LCD color
GraphicsWindow.FillRectangle(LCD_iWX0, LCD_iWY0, iWidth, iHeight)
GraphicsWindow.FontName = LCD_sFontName
GraphicsWindow.FontSize = LCD_iFontSize
GraphicsWindow.BrushColor = "Black" ' LCD digits color
GraphicsWindow.DrawText(LCD_iEX0, LCD_iEY0, Calc_sExp)
EndSub
'
Sub Button_DrawNumKeys
GraphicsWindow.FontName = Body_sFontName
GraphicsWindow.FontSize = Body_iFontSize
For j = 1 To 5
iY = Button_iY0 + (j - 1) * Button_idY
For i = 1 To 4
iX = Button_iX0 + (i - 1) * Button_idX
bPushed = "False"
If i = 4 And j = 5 Then
ElseIf i = 3 And j = 5 Then
bLong = "True"
Button_DrawNumKey()
Else
bLong = "False"
Button_DrawNumKey()
EndIf
EndFor
EndFor
EndSub
'
' in: iX, iY - key possition
' in: bLong - flag key size is long
Sub Button_DrawNumKey
If bLong Then
iWidth = Button_iWidth * 2 + Button_iGX
Else
iWidth = Button_iWidth
EndIf
GraphicsWindow.BrushColor = "DimGray" ' button frame color
GraphicsWindow.FillRectangle(iX, iY, iWidth, Button_iHeight)
If i = 1 And j = 1 Then
GraphicsWindow.BrushColor = "Chocolate" ' button shadow color 2
Else
GraphicsWindow.BrushColor = "Black" ' button shadow color 1
EndIf
iDX0 = iX + 6
iDY0 = iY + 6
iDX1 = iDX0 + iWidth - 10
iDY1 = iDY0 + Button_iHeight - 10
GraphicsWindow.FillRectangle(iDX0, iDY0, iDX1 - iDX0, iDY1 - iDY0)
If bPushed Then
iPX = 8
iPY = 8
Else
iPX = 4
iPY = 4
EndIf
iUX0 = iX + iPX - 4
iUX1 = iUX0 + iWidth - 10
iUY0 = iY + iPY - 4
iUY1 = iUY0 + Button_iHeight - 10
GraphicsWindow.FillTriangle(iUX1, iUY0, iUX1, iDY0, iDX1, iDY0)
GraphicsWindow.FillTriangle(iUX0, iUY1, iDX0, iUY1, iDX0, iDY1)
If i = 1 And j = 1 Then
GraphicsWindow.BrushColor = "DarkOrange" ' button surface color 2
Else
GraphicsWindow.BrushColor = "DimGray" ' button surface color 1
EndIf
GraphicsWindow.FillRectangle(iUX0, iUY0, iUX1 - iUX0, iUY1 - iUY0)
GraphicsWindow.BrushColor = "White" ' button digit color
GraphicsWindow.DrawText(iX + iPX + Button_iX[i][j], iY + iPY, Button_sKey[i][j])
EndSub
'
Sub Button_InputKey
EndSub
'
Sub Calc_EvalExp
EndSub