You are on page 1of 7

CD206 BUSINESS PROGRAMMING (Tutorial 3) (L3B-4) GohWei Keat id: 1002162301

1- List some of the benefits of working with Multiple Controls.


i) Drag a group of selected controls to move the entire group to a new location at one
time.
ii) Set common properties
iii) Use Format Menu or Layout Toolbar to
– Align controls to each other
– Make controls the same size
– Modify the spacing between controls
2- Visual Basic has three modes in which it operates. Briefly explain the THREE (3)
modes.
The 3 modes are Design Mode, Run Mode, and Break Mode.
i. Design Mode (or Design Time) is the mode in which you create the
application.
ii. Run Mode (or Run Time) executes the application in the Visual Studio
environment.
iii. Break Mode momentarily suspends execution of a running application and is
for testing and debugging purposes.
3- When user click on RadioButton_red, the color of text box will be changed to red.
And the same action with other radio boxes. Design the GUI using Visual Basic.Net
and write the code.
CD206 BUSINESS PROGRAMMING (Tutorial 3) (L3B-4) GohWei Keat id: 1002162301
CD206 BUSINESS PROGRAMMING (Tutorial 3) (L3B-4) GohWei Keat id: 1002162301

Public Class Form1

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click


Close()
End Sub

Private Sub RadioButton4_CheckedChanged(sender As Object, e As EventArgs) Handles


RadioButton4.CheckedChanged
TextBox1.BackColor = Color.Green
End Sub

Private Sub RadioButton3_CheckedChanged(sender As Object, e As EventArgs) Handles


RadioButton3.CheckedChanged
TextBox1.BackColor = Color.Yellow
CD206 BUSINESS PROGRAMMING (Tutorial 3) (L3B-4) GohWei Keat id: 1002162301

End Sub

Private Sub RadioButton2_CheckedChanged(sender As Object, e As EventArgs) Handles


RadioButton2.CheckedChanged
TextBox1.BackColor = Color.Blue
End Sub

Private Sub RadioButton1_CheckedChanged(sender As Object, e As EventArgs) Handles


RadioButton1.CheckedChanged
TextBox1.BackColor = Color.Red
End Sub

End Class

4- Differentiate between Constants and variables.


A constant is a data item whose value cannot change during the program's execution.
Thus, as its name implies – the value is constant. E.g. sales tax rate, Pi, e

A variable is a data item whose value can change during the program's execution.
Thus, as its name implies – the value can vary. E.g. customer’s name, price, width

5- Differentiate between Declaration, Initialization, and Assignment of variables in


VB.net.
Declaration: a declaration states the type of a variable, along with its name. A variable
can be declared only once. It is used by the compiler to help programmers avoid
mistakes such as assigning string values to integer variables. Before reading or
assigning a variable, that variable must have been declared.

Initialization: it's a special kind of assignment: the first. Before initialization objects
have null value and primitive types have default values such as 0 or false. Can be
done in conjunction with declaration.

Assignment: throwing away the old value of a variable and replacing it with a new
one

6- Explain the ways of assigning values to variables in VB.net.


- Getting your data into a variable
- Using the equals sign (=)
- Make sure all variables are first declared before assignment
7- State THREE (3) of the naming rules in vb.net.
a) must start with a letter or underscore
b) cannot have spaces
c) cannot use special characters
8- Define the following: -
CD206 BUSINESS PROGRAMMING (Tutorial 3) (L3B-4) GohWei Keat id: 1002162301

(i) Scope of Variables


Scope refers to the part of the program where a variable is visible and may be
accessed by program code
(ii) Lifetime of Variables
Lifetime of a variable is the period of time the variable exists. When a
procedure terminates, all local variables will come to the end of its lifetime.
The values of its local variables are not preserved and VB reclaims their
memory. Next time the procedure is called, its local variables will be created
afresh and reinitialized.
9- Reorder the following operations according to the order of precedence from highest
to lowest. (Integer division, Multiplication and Division, Modulus, Parentheses,
Addition and Subtraction, Exponentiation)
Parentheses, Exponentiation, Multiplication and Division, Integer division, Modulus,
Addition and Subtraction
10- Differentiate between Widening & Narrowing Conversion. Support your answer with
example.

11- Specify runtime errors in the following statements


a- Dim intCount As Integer = "123A"
A is not an integer, it is a Character

b- Dim 2intAge As Integer = 4


Name must start with a letter or underscore

c- Dim datBirth As Date = CDate("11/32/2011")


the month only contain 01 until 12
CD206 BUSINESS PROGRAMMING (Tutorial 3) (L3B-4) GohWei Keat id: 1002162301

d- Dim dblPayroll As Double = CDbl("123")


double cannot put ( )

e- FirstNum + SecondNum = Total


Must declare the variables first

12- Evaluate the following expressions. Show evaluation steps in your answer.
(i) (45 + 2^2 \ 15) Mod 5 – 2
= (45 + 4 \ 15) Mod 5 -2
= (45 + 0) Mod 5 – 2
= 45 Mod 5 – 2
=0–2
= -2
(ii) (5 \ 2 + 3 / 2) >= 3 AND false
(5 \ 2 + 1.5) >= 3
(2 + 1.5) >= 3
3.5 >= 3 AND false
TRUE AND FALSE
FALSE
13- Differentiate between Explicit and Strict options in VB.net. State the default value for
each option.

14- What is wrong with each of the following?


a. shoNum + shoNum2 = shoTotal
Must declare the variables first
b. Dim decPrice As Decimal = " $4.99 "
cannot put dollar symbol and must include( )
c. shoCube = (shoSide) 3
must put ^
15- What is the value of x after each statement is performed?
a. x = 7 + 3 * 3 \ 2 – 1
=7+9\2–1
=7+8–1
x = 14
b. x = 2 Mod 2 + 2 * 2 - 2 / 2
= 2 Mod 2 +4 – 1
=0+4–1
x=3
CD206 BUSINESS PROGRAMMING (Tutorial 3) (L3B-4) GohWei Keat id: 1002162301

c. x = (3 * 9 * (3 + (9 * 3 / (3))))
= (3 * 9 *(3 + (27 / 3)))
= (3 * 9 * (3 + 9))
= (27 * (12))
x = 324

d. x = 6 * 2 ^ 3 + 4 / 2
=6*8+2
x = 50

e. x = 6 / 2 * 2 ^ 3 + 4
=6/2*8+4
=3*8+4
x = 28
16- Given z = 8e5-n write in VB expression.
z=8*e^5–n

17- Complete the following table

Number Value Format String ToString() Value


12.3 N3 12.300
12.348 n2 12.35
1234567.1 n 1,1234567.10234,567.10
123456.0 f2 123456.00
123456.0 e3 123456.000
.234 p 23.4%
–1234567.8 c ($1234567.8)

END OF QUESTION

You might also like