Professional Documents
Culture Documents
VB statements Case
expression list 2
VB Statements Case
expression list 3
VB statements Case
expression list 4
Case Else
VB Statements
End Select
Example (1): Write a program to enter the value of variable (Mark). Find
the grade using Case statement and display the value of grade in a text
End Select
• Select Case X
End Sub
• Select Case X
End Select
Example (2): Design a form with four text boxes and three commands.
Design the program so that the values of num1, num2, and Symbol are
entered into separate three text boxes. Write a code to perform (add,
subtract, multiply and divide) when pressing on command (Calculate).
Display the result in separate text box. The command (Clear) used to clear
values in text boxes. Click command (Exit) to end the program and return
to the project window.
Solution:
Symbol = Text2.Text
y = CDbl(Text3.Text)
z=x/y
Case Else
GoTo 10
End Select
Text4.Text = Str(z)
10 End Sub
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
End
Exercise (1): Create a Visual Basic project to solve for the roots of the
quadratic equation 𝒂 𝑿𝟐 + 𝒃X+ 𝒄 = , using quadratic formula as:
√
X1,2 = .
Design the program so that the values of coefficient a, b, and c are entered
by using input box statement. Display number of roots and value of roots
in text boxes. When the value of coefficient (a) equal to zero or(𝒃𝟐 − 𝟒𝒂c)
less than zero, write a message box to enter a new value of coefficients or
end the program.
Exercise (2): Create a Visual Basic project to find the value of function
f(Z) from the equations are below. Write a code so that the value of
variables Y and Z are entered into two boxes. Display the value of function
f (Z) in separate picture box when click command button. Design form
window and select all the control objects are used.
Exercise (3): Use the Newton Raphson method to estimate the root of
the function 𝑒−𝑋 = x , employing initial value of 𝑋old= 0.0 . Write visual
Basic code to compute the root 𝑋new . Print the value of 𝑋new when the
value of|𝑋new − 𝑋old| ≤ 0.0001. Design the form with two text box and one
command button.