Showing posts with label Controls. Show all posts
Showing posts with label Controls. Show all posts

Thursday, September 27, 2012

Small Basic: A Simple Addition Program

Here is a simple Microsoft Small Basic Program that adds two numbers and displays the answer.

'Create a Graphics Window
GraphicsWindow.Show()
'Create caption and text box for the first variable
GraphicsWindow.DrawText(20,20,"Enter First Number")
typedvar1 = Controls.AddTextBox(200,20)
'Create caption and text box for the second variable
GraphicsWindow.DrawText(20,120,"Enter Second Number")
typedvar2 = Controls.AddTextBox(200,120)
'Create caption and text box for the answer
GraphicsWindow.DrawText(20,220,"The answer is")
Answer1 = Controls.AddTextBox(200,220)
'Create a button for adding the two variables
Controls.AddButton("Add", 220,400)
'The answer goes in textbox labeled Answer1
Controls.SetTextBoxText(Answer1, "  ")
'Execute subroutine named buttonsub when add button is clicked
Controls.ButtonClicked = buttonsub
'Subroutine executed when add button is clicked
Sub buttonsub
  'fetch two numbers entered
  var1 = Controls.GetTextBoxText(typedvar1)
  var2 = Controls.GetTextBoxText(typedvar2)
  'Add the two numbers
  var3 = var1 + var2
  'Display the sum in the textbox named answer1
  Controls.SetTextBoxText(Answer1,var3)
EndSub



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