- Explain the process of naming a variable, declaring a variable, assigning a variable.
- When naming a variable you want to make the name similar to the object so that you know what it is.
EX.) I have a button with a value of Exit. I would name it something like exitButton, or exitBtn.
- When declaring a Variable you say: Dim name As String, Integer, or Decimal
- When you want to assign a variable to something you use: name of variable = text or object.
-Review Practice: Chapter 3
Short answer-
Questions - pg. 188 - 189
1. Assume a procedure needs to store an item's name and its price. The price may have a decimal place. Write the appropriate Dim statements to create the necessary procedure-level variables.
Dim items name as String
Dim price name as Decimal
Dim isconverted as Boolean
isConverted = Decimal.Tryprase(textboxname,
2. Assume a procedure needs to store the name of an item in inventory and its height and weight. The height has decimal places; the weight will be whole numbers only. Write the appropriate Dim statements to create the necessary procedure-level variables.
Dim nameofinventoryitem As String
Dim heightofitem As Decimal
Dim weightofitem As Integer
Dim isconverted> As Boolean
3. Write an assignment statement that assign Miami to an existing String variable named city.
Dim cityName As String
cityName = textbox1.Text
cityLabel.Text = cityName
4. Write an assignment statement that adds the contents of the sales1 variable to the contents of sale2 variable, and then assigns the sum to an existing variable named totalSales. All of the variables have the Decimal data type.
Dim sales1 As Decimal
Dim sales2 As Decimal
Dim totalSales As Decimal
sales1 = content
sales2 = content
totalSales = sales1 + sales2
Label1.Text = totalSales
5. Write an assignment statement that multiplies the contents of the salary variable by the number 1.5, and then assign the result to the salary variable. The salary variable has the Decimal data type.
Dim getsalary As Decimal
Dim salary As Decimal
Const times As Decimal = 1.5
salary = getsalary * times
6. Assume a form contains 2 buttons named salarybutton and bonusbutton. Both buttons Click event procedures need to use the same variable, which is a string variable named employeeName. Write the appropriate statement to declare the employeeName Variable. Also specify where you will need to enter the statement and whether the variable is a procedure-level or module-level variable.
Dim employeeName As String
employeeName = employeeNameTextBox.Text
Public Sub salaryButton_Click()
If employeeName == name Then
MessageBox.Show(employeeName & "salary is amount)
Else
MessageBox.Show("You did not enter name.")
End If
End Sub
9. Write the statement to convert the contents of the unitsTextBox to an integer. Store the Integer is an Integer Variable named numberofunits. Us isConverted as the name of the Boolean.
Dim unitsenter As String
Dim numberofunits As Integer
Dim isConverted As Boolean
unitsenter = unitsTextBox.Text
isConverted = Integer.TryParse(unitsenter, numberofunits)
15. What is a static Variable?
Is a procedure-level variable that retains its value even when the procedure in which it is declared ends.
Chapter 3 -> Pg.260 Writing Statements
Chapter 4 -> Pg.260
7. Write an If...Then...Else statement that displays the string "Pontiac" in the carmakerLabel when the carTextBox contains the string "Grand Am".
Dim carname As String
carname = carTextBox.Text
If carname = "Grand Am" Then
carMakerLabel.Text = "Pontiac"
Else
MsgBox("NO RIGHT")
carMakerLabel.Text = " "
End If
8. Write an If..Then..Else statement that displays the string "Entry error" in the message Label then the units variable contains a number that is less than 0; Otherwise, assign the String "OK".
Dim numberenter As Integer
Dim error As String = "Entry Error"
Dim passes As String = "OK"
Dim isConverted As Boolean
isConverted = Integer.TryParse(NumberTextBox.Text, numberenter)
If numberenter < 0 Then
MessageLabel.Text = error
Else
MessageLabel.Text = passes
End If
13.
Dim hours As Integer
Dim hourRate As Integer
Dim gross As Integer
If hours = 40 Then
gross =
ElseIf hours > 40 Then
gross = number + hourRate
End If

No comments:
Post a Comment