Tuesday, August 28, 2012

Microsoft Small Basic: A Simple Program With Two Buttons

Here is a simple Small Basic program that uses two buttons. When a button is pressed, a window message pops up naming the button that was pressed.


GraphicsWindow.Show()
'Add the button labeled Exit
ExitButton = Controls.AddButton("Exit",20,50)
'Add the button labeled Hello
HelloButton = Controls.AddButton("Hello",20,20)
'When a button is clicked, call the ButtonsBeenClicked subroutine
Controls.ButtonClicked=ButtonsBeenClicked

Sub ButtonsBeenClicked
  'If the Hello button was clicked, display the message Hello Button Presssed
  If controls.LastClickedButton = HelloButton then
    GraphicsWindow.ShowMessage("Hello Button Pressed","Button Message")
    'Else if the Exit button was clicked, display the message Exit Button Pressed
    ElseIf controls.LastClickedButton = ExitButton then
      GraphicsWindow.ShowMessage("Exit Button Pressed","Button Message")
  EndIf
EndSub




1 comment:

Anonymous said...

Very good to learn! Congratulations!