' Calculator interface demo, doesn't do anything, just to demonstrate the
' use of array of components.

DECLARE SUB ButtonClick (Sender AS QBUTTON)

CONST FALSE = 0
CONST TRUE = 1

DIM Form AS QForm
    Form.Width = 320
    Form.Height = 270
DIM Buttons(1 TO 4, 1 TO 5) AS QBUTTON
DIM Edit AS QEdit
DIM I AS INTEGER, J AS INTEGER, N AS INTEGER

FOR I = 1 TO 3
  FOR J = 1 TO 5
    Buttons(I,J).Parent = Form
    Buttons(I,J).Top = 200-I*50
    Buttons(I,J).Left = (J-1)*50+30
    Buttons(I,J).Width = 51
    Buttons(I,J).Height = 51
    SELECT CASE J
      CASE 4
        IF I = 1 THEN
          Buttons(I,J).Caption = "+"
        ELSEIF I = 2 THEN
          Buttons(I,J).Caption = "*"
        ELSE
          Buttons(I,J).Caption = "+/-"
        END IF
      CASE 5
        IF I = 1 THEN
          Buttons(I,J).Caption = "-"
        ELSEIF I = 2 THEN
          Buttons(I,J).Caption = "/"
        ELSE
          Buttons(I,J).Caption = "%"
        END IF
      CASE ELSE
        Buttons(I,J).Caption = STR$((I-1)*3+J)
    END SELECT
    Buttons(I,J).OnClick = ButtonClick
  NEXT
NEXT
Buttons(4,1).Parent = Form
Buttons(4,1).Top = 200
Buttons(4,1).Left = 30
Buttons(4,1).Width = 101
Buttons(4,1).Height = 51
Buttons(4,1).Caption = "0"
Buttons(4,1).OnClick = ButtonClick
Buttons(4,2).Parent = Form
Buttons(4,2).Top = 200
Buttons(4,2).Left = 130
Buttons(4,2).Width = 51
Buttons(4,2).Height = 51
Buttons(4,2).Caption = "."
Buttons(4,2).OnClick = ButtonClick
Buttons(4,3).Parent = Form
Buttons(4,3).Top = 200
Buttons(4,3).Left = 180
Buttons(4,3).Width = 101
Buttons(4,3).Height = 51
Buttons(4,3).Caption = "="
Buttons(4,3).OnClick = ButtonClick


Edit.Parent = Form
Edit.Top = 5
Edit.Left = 30
Edit.Width = 250
Edit.Height = 30
Edit.Enabled = 0

Form.Center
Form.ShowModal


SUB ButtonClick (Sender AS QBUTTON)
  Edit.Text = Edit.Text + Sender.Caption
END SUB
