0% found this document useful (0 votes)
2K views5 pages

Practical No 03 Gad 22034

This document provides instructions and code for a practical assignment to create a message box program that performs arithmetic expressions in Visual Basic.NET. It includes details on using the MessageBox and InputBox functions to display results of addition, subtraction, multiplication and division of two input numbers. Sample code is provided to demonstrate getting input from the user, performing calculations, and displaying results in message boxes. The document also includes related questions about the differences between MessageBox and ErrorProvider and types of message boxes.

Uploaded by

AB ESPORTS
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2K views5 pages

Practical No 03 Gad 22034

This document provides instructions and code for a practical assignment to create a message box program that performs arithmetic expressions in Visual Basic.NET. It includes details on using the MessageBox and InputBox functions to display results of addition, subtraction, multiplication and division of two input numbers. Sample code is provided to demonstrate getting input from the user, performing calculations, and displaying results in message boxes. The document also includes related questions about the differences between MessageBox and ErrorProvider and types of message boxes.

Uploaded by

AB ESPORTS
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Practical No. 3: Implement a Message Box program & Arithmetic Expressions.

Practical No: 03

VIII. Resources required (Additional)


- If any web reference is required.

X. Resources required (Actual)


(1) https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-features
/operators-and-expressions/arithmetic-operators
(2) https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.messagebox?View=
netframework-4.7.2

XI. Program Code:


Write a program using MessageBox and Arithmetic Expressions –

Module Module1
Dim i, j, r As Integer

Sub Main()
Console.WriteLine("Enter First Value=")
i = Console.ReadLine()
Console.WriteLine("Enter Second Value=")
j = Console.ReadLine()
Console.ReadLine()
MsgBox("Addition =" & (i + j))
MsgBox("Substraction =" & (i - j))
MsgBox("Multiplication =" & (i * j))
MsgBox("Division =" & (i / j))
End Sub
End Module
Results (Output of the Program)
Enter First Value=
10
Enter Second Value=
5
---------------------------
MessageBoxPractical3
---------------------------
Addition =15
---------------------------
OK
---------------------------

GUI Application Development using VB.Net (22034) Page 1


Practical No. 3: Implement a Message Box program & Arithmetic Expressions.

XIII. Practical Related Questions


1. Write the difference between MessageBox() and ErrorProvider Control –
- Displays a message window, also known as a dialog box, which presents a message to the
user. It is a modal window, blocking other actions in the application until the user closes it.
A MessageBox can contain text, buttons, and symbols that inform and instruct the user.
- Sets the error description string for the specified control. When an error occurs for the value
in associated control, then a small red color icon is displayed and when we hover the mouse
on icon it displays an error message.

2. Describe any four types of MessageBox() Window –


In Visual Basic, MessageBox has Show() method and it is overloaded to create various
types of MessgeBoxes and various programming situations –

It has prototype –
DialogResult Show(String text, String caption, MessageBoxButtons buttons,
MessageBoxIcon icon, MessageBoxDefaultButton defaultButton)
This method is static and doesn’t required and object reference. The parameters and return
values are explained below –

Parameters
1. text As String - The text to display in the message box.
2. caption As String - The text to display in the title bar of the message box.
3. buttons As MessageBoxButtons - One of the MessageBoxButtons values that
specifies which buttons to display in the message box.
4. icon As MessageBoxIcon - One of the MessageBoxIcon values that specifies which
icon to display in the message box.
5. defaultButton As MessageBoxDefaultButton - One of the
MessageBoxDefaultButton values that specifies the default button for the message
box.

Returns
DialogResult - One of the DialogResult values.

GUI Application Development using VB.Net (22034) Page 2


Practical No. 3: Implement a Message Box program & Arithmetic Expressions.

XIV. Exercise
1. Implement the program to generate result of any arithmetic operation using
MessageBox().


Public Class Form1


Dim n As Integer
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
n = Val(TextBox1.Text) + Val(TextBox2.Text)
MsgBox("Addition=" & n)
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
n = Val(TextBox1.Text) - Val(TextBox2.Text)
MsgBox("Substraction=" & n)
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
n = Val(TextBox1.Text) * Val(TextBox2.Text)
MsgBox("Multiplication=" & n)
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
n = Val(TextBox1.Text) / Val(TextBox2.Text)
MsgBox("Division=" & n)
End Sub
End Class

-Arithmetic Operation using msgbox

Addition=60

OK

GUI Application Development using VB.Net (22034) Page 3


Practical No. 3: Implement a Message Box program & Arithmetic Expressions.

2. Write a program using InputBox(), MessageBox() & perform various Arithmetic


expressions.


Public Class Form1


Dim i, j, r As Integer

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click


i = InputBox("Enter First Value")
j = InputBox("Enter Second Value")
r = Val(i) - Val(j)
MsgBox("Substract = " & r)
End Sub

Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click


i = InputBox("Enter First Value")
j = InputBox("Enter Second Value")
r = Val(i) / Val(j)
MsgBox("Divide = " & r)
End Sub

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click


i = InputBox("Enter First Value")
j = InputBox("Enter Second Value")
r = Val(i) * Val(j)
MsgBox("Multiply = " & r)
End Sub

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


i = InputBox("Enter First Value")
j = InputBox("Enter Second Value")
r = Val(i) + Val(j)
MsgBox("Addition = " & r)

End Sub
End Class

GUI Application Development using VB.Net (22034) Page 4


Practical No. 3: Implement a Message Box program & Arithmetic Expressions.

Output:

Inputbox_Msgbox

Addition = 68

OK

GUI Application Development using VB.Net (22034) Page 5

You might also like