Showing posts with label button. Show all posts
Showing posts with label button. Show all posts

Sunday, March 2, 2014

Microsoft Small Basic: A Simple Program Handling Multiple Events

Here is a simple Microsoft Small Basic program that handles multiple events. A graphics window is displayed with a text box and a button.

Every time the user uses the mouse to click on the button, the message 'Button Clicked Event Raised' is displayed in a message window. The user acknowledges the message by clicking on the 'OK' button in the message window.

Click the mouse in the text box window. When the user types a letter or number in the text box window,  the message 'Text Typed Event Raised' appears in a message window. The user acknowledges the message by clicking on the 'OK' button in the message window.


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