There are many times when we need our programs to store values for later use. We store values in 'variables' so that we may access their values whenever we need them.
We are going to edit our Payroll program to store the hours, hourly pay and total pay in variables.
Make sure to give variables meaningful names, and use the proper prefix for the type of data that they will store.
Dim intAge as Integer 'Declare the variable
intAge = 15 'Assign a value to the variable
lblOutput.Text = "You are " & intAge & " years old!" 'Use variable
Dim dblPrice as Double 'Declares variables that can store decimal numbers
Dim dblTax as Double
Dim dblTotal as Double
dblPrice = 10.99 'Assigns values to dblPrice and dblTax
dblTax = 1.13
dblTotal = dblTax * dblPrice 'Calculates final price
lblTotalPrice.Text = "$" & dblTotal 'Outputs final price with '$' in front
Dim strName as String 'Declare variable that can store words
strName = "Mr. Aldworth" 'Assign a value to variable using " "
lblGreeting.Text = "Welcome " & strName 'Use variable to output a nice greeting
We are going to edit our Payroll program to display our monetary values as properly formatted currency.
If you finish, attempt the VB Color Application for bonus marks.