In: Computer Science
Please note: This is in Visual Basic.
Create an application. Add two text boxes, a label, and a button to the form. The button’s Click event procedure should assign the contents of the text boxes to Double variables named dblNum1 and dblNum2. It then should divide the dblNum1 variable’s value by the dblNum2 variable’s value, assigning the result to a Double variable named dblAnswer. Display the answer in the label. Code the procedure. Save the solution and then start the application. Test the application using the numbers 6 and 2; the number 3 appears in the label control. Now test it using the numbers 6 and 0. The infinity symbol (∞) appears in the label control because the application is trying to divide a number by 0. Add a selection structure to the procedure. The selection structure should perform the division and display the quotient only if the value in the dblNum2 variable is not 0; otherwise, it should display N/A in the label. Save the solution and then start and test the application. Close the solution.
Dear Student ,
As per the requirement submitted above , kindly find the below solution.
Here a new Windows Forms Application in VB is created using Visual Studio 2017 with name "VBAppDivide".This application contains a form with name "Form1.vb".Below are the files associated with form1.
1.Form1.vb[Design]
2.Form1.vb
'VB class
Public Class Form1
'Divide button click
Private Sub btnDivide_Click(sender As Object, e As EventArgs)
Handles btnDivide.Click
'declaring inputs and taking inputs entered by user
Dim dblNum1 As Double = Double.Parse(txtFirstNumber.Text)
'taking second number
Dim dblNum2 As Double = Double.Parse(txtSecondNumber.Text)
'declaring variable to store answer
Dim dblAnswer As Double
dblAnswer = dblNum1 / dblNum2
'using if else checking second number dblNum2
If dblNum2 > 0 Then
'if dblNum2 is not zero then
'display result in the textbox
lblResult.Text = dblAnswer
Else
'otherwise display NA
'display result in the textbox
lblResult.Text = "N/A"
End If
End Sub
End Class
======================================================
Output : Run application using F5 and will get the screen as shown below
Screen 1 :
Screen 2:Screen when second number is 0
Screen 3:Screen showing division
NOTE : PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.