Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
06 Laboratory Exercise 1
Operators and Array
Objectives:
use operators
apply array
Materials:
Basic Principles:
Operators and arrays are useful when it comes to programming. It helps the program to make
decision within condition. With this activity, the student will understand the use of operators and
arrays on developing programs.
Procedures:
1. Open a new project and name it as OpAndArray. This will also serve as Challenged Exercise.
2. Add 17 Button Control and 1 Textbox Control to design a simple calculator.
3. Change the Name Property of Button Controls as follows:
• Button1 – btnClear • Button10 – btn4
• Button2 – btnDivide • Button11 – btn5
• Button3 – btnMultiply • Button12 – btn6
• Button4 – btnSubtract • Button13 – btn7
• Button5 - btnAdd • Button14 – btn8
• Button6 – btnEqual • Button15 – btn9
• Button7 - btn1 • Button16 - btn0
• Button8 - btn2 • Button 17 - btnDecimal
• Button9 – btn3
NOTE: firstNum and secondNum are variables declared to hold the two (2) input values
to be computed, ans is the variable for the output and operation is used for declaring
the operation to use. Single is the data type used for the first three variable because it
could contain floating-point numbers that do not need the full data width.
6. Type the code below for:
• Button 1:
txtDisplay.Text = 1
• Button 2:
txtDisplay.Text = 2
• Button 3:
txtDisplay.Text = 3
7. Run the program. Click the 1, 2, and 3 button and observe what happened.
NOTE: When you click on one of the three buttons its corresponding value will appear in the
Textbox, but it will be replaced when another button is clicked.
8. Now, challenge yourself to come up with the appropriate code that will keep the value in
Textbox even when another button is clicked before executing the operation.
9. Copy the code below for plus and minus button.
NOTE: The operation to be executed depends on the value of the variable operation of
each button which is connected to the equal button.
10. Copy the code below for equal button.
NOTE: Conditional statement is used to make decision on which operation will be executed
based from the button clicked. The variable operation contains conditions that have
corresponding actions to be executed when a certain condition is met.
11. Run the program. Click the buttons 1, 2, 3, +, -, and = to perform calculation.
12. Finish the activity by completing the codes of the simple calculator. Save your work.
MsgBox(num(1))
MsgBox(num(2))
MsgBox(num(3))
MsgBox(num(4))
End Sub