Tuesday, August 17, 2010

Variables

Variables are "containers" for values that can be used by a program. Variables can contain numbers or text. Variables are given names so they can be referred to in the programming code.

Today, I will create three variables, one called "point", one called "number", and one called "name".

Program used: Microsoft Visual Basic
Once I had a new form, I had to add three buttons from the toolbox to the form and change the names from:
* Button1 to Whole Number
* Button2 to Decimal Number
* Button3 to Name
I then added 3 Labels one beside each of the buttons and then a text box below the Name button.

I then changed the codes for the buttons:
Private Sub Button1_Click (ByVal sender As System. Object, ByVal e As System. EventArgs)
Handles Button1.Click
number = Rnd ()
Label1.Text = number
End Sub


Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System. EventArgs)
Handles Button2.Click
point = Rnd ()
Label2.Text = point
End Sub

Private Sub Button3_Click (ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button3.Click
myname = TextBox1.Text
Label3.Text = myname
End Sub

The following are the screenshots of my end result for this class task.
T
he first screenshot is of the codes which is what makes the program run.
The second screenshot is of the actual program/form that I made.

No comments:

Post a Comment