Test your knowledge - click here
So far we have learnt to output a message. Now we are going to look at inputting and then getting the computer to output it. When we input data the computer stores this in an area of memory. We DECLARE the area of memory by setting up a DIM statement which creates the area. We then assign that area with a NAME known as a VARIABLE. Each variable has a data type assigned so we tell the computer what type of data will be stored in that area.
Example
Dim FirstNumber as Integer
Dim - Declare or make an area
FirstNumber - Call the area Firstnumber (this will be where we store the Firstnumber variable
As Integer - We will be storing whole numbers in that area
We then write code to get the user to input a number which we then store in that area. This is known an a Variable.
Example
FirstNumber = InputBox("Please enter a number")
FirstNumber - is the area we made to store the number
InputBox - produces a box for the user to type in the number which then gets stored in the area FirstNumber
Please read this link for further information on variables
Class Exercise - Task 3
In the previous exercise, we have outputted onto a MESSAGE BOX.
Now we are going to INPUT 2 numbers using a INPUTBOX, ADD them together and then OUTPUT the answer using a MESSAGE BOX.
Watch the video to help you with this task
The basic operators that can be used are shown in the table below:
Make buttons to Subtract, Multiply and Divide the two numbers entered. (HINT - If your answers is coming out correct for these then have a look at the next page and you may need to change the data type from Integer to store a decimal).
Change the back colour and fore colour of the buttons.
Change the back colour and fore colour of the form
Calculate the Average of the number entered. Extend to add more than two numbers
Write an application in Visual Basic that calculates the area of a circle.
Area = radius x radius x pi (pi = 3.142)
Add features to calculate the area of a triangle and a rectangle.
(HINT - If your answers is coming out correct for these then have a look at the next page and you may need to change the data type from Integer to store a decimal).