Question

In: Computer Science

Create an ASP.Net Website using Visual Studio with Visual Basic.Net: Create a simple calculator that has...

Create an ASP.Net Website using Visual Studio with Visual Basic.Net:

Create a simple calculator that has 3 text boxes: 2 of them to enter numbers, the 3rd one displays the results

Create 4 buttons to add, subtract, multiply, and divide

Prevent the user from entering text in the number fields

Display a message indicating “cannot divide by” when the user click “/” and there is a zero the in the second box

Create two additional buttons:

- One to store data - The store data will store the results into array

- One to display data - The display data will display the contents of the array (use 10 for the array size)

Solutions

Expert Solution

Dear Student ,

As per the requirement submitted above , kindly find the below solution.

Here a new Asp.net web site in VB is created using Visual Studio with name "CalculatorUsingVB".This website contains a web page with name "WebForm.aspx".Below are the details of this web page.

WebForm.aspx :

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm.aspx.vb" Inherits="CalculatorUsingVB.WebForm" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<%-- title for web page --%>
<title>simple calculator using VB.net</title>
<%-- <script> is used for javascript --%>
<script>
//function to validate user inputs
function allowNumbers(e) {
var unicode=e.charCode? e.charCode : e.keyCode
       if (unicode!=8)
{
//allow backspace
       if (unicode<48||unicode>57) //if not a number
               {
       return false //disable key press
               }
      
       }
           else
           {
               return true;
           }
}
  

</script>
</head>
<body>
<form id="form1" runat="server">
Number 1:
<%-- textbox for first number --%>
<asp:TextBox ID="txtNumber1" runat="server" onkeypress="return allowNumbers(event);"></asp:TextBox>
<br />
<br />
Number 2 :
<asp:TextBox runat="server" ID="txtNumber2" onkeypress="return allowNumbers(event);"></asp:TextBox>
<br /> <br />
Result :&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:TextBox runat="server" ID="txtResult"></asp:TextBox>
<br />
<br />
<br />
<%-- buttons --%>
<asp:Button runat="server" ID="btnPlus" Text="+" />
&nbsp;<asp:Button runat="server" ID="btnMinus" Text="-"/>
&nbsp;<asp:Button runat="server" ID="btnMultiply" Text="x" />
&nbsp;<asp:Button runat="server" ID="btnDivide" Text="/" />
&nbsp;<asp:Button runat="server" ID="btnStore" Text="Store" />
&nbsp;<asp:Button runat="server" ID="btnDisplay" Text="Display" />
<br />
<br />
<%-- label ti display array data --%>
<label id="lblHeader" runat="server" />
</form>
</body>
</html>

********************************

WebForm.aspx.vb :

Public Class WebForm
Inherits System.Web.UI.Page
'declaring array to store results
Shared arr(10) As Double
'declaring variable
Shared i As Integer = 0
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

End Sub
'Plus button click
Protected Sub btnPlus_Click(sender As Object, e As EventArgs) Handles btnPlus.Click
'take numbers entered by user , parse it into integer and display result in the textbox
txtResult.Text = Integer.Parse(txtNumber1.Text) + Integer.Parse(txtNumber2.Text)

End Sub
'Minus button click
Protected Sub btnMinus_Click(sender As Object, e As EventArgs) Handles btnMinus.Click
'take numbers entered by user , parse it into integer and display result in the textbox
txtResult.Text = Integer.Parse(txtNumber1.Text) - Integer.Parse(txtNumber2.Text)
End Sub
'Multiply button click
Protected Sub btnMultiply_Click(sender As Object, e As EventArgs) Handles btnMultiply.Click
'take numbers entered by user , parse it into integer and display result in the textbox
txtResult.Text = Integer.Parse(txtNumber1.Text) * Integer.Parse(txtNumber2.Text)
End Sub
'divide button click
Protected Sub btnDivide_Click(sender As Object, e As EventArgs) Handles btnDivide.Click
'checking if second number is zero or not
If Integer.Parse(txtNumber2.Text) = 0 Then
'display message
txtResult.Text = "cannot divide by 0"
Else
'take numbers entered by user , parse it into integer and display result in the textbox
txtResult.Text = (Integer.Parse(txtNumber1.Text) / Integer.Parse(txtNumber2.Text)).ToString("0.00")
End If
End Sub
'store button click
Protected Sub btnStore_Click(sender As Object, e As EventArgs) Handles btnStore.Click
arr(i) = Double.Parse(txtResult.Text) 'store result in the array
i = i + 1 'increment value of i
End Sub
'disply button click
Protected Sub btnDisplay_Click(sender As Object, e As EventArgs) Handles btnDisplay.Click
Dim result As String = ""
'Using for loop
For index = 0 To arr.Length - 1
'checking if result is not zero then display
If arr(index) = 0 Then
'if value is zero do nothing
Else
result = result & arr(index) & " " 'display each array element in the label
End If
lblHeader.InnerText = result
Next
End Sub
End Class

======================================================

Output : Run application using F5 and will get the screen as shown below

Screen 1 :WebForm.aspx

Screen 2 :Screen showing addition and when display button clicked getting result from the array

NOTE : PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.


Related Solutions

Create an ASP.Net Website using Visual Studio with C#: Create a simple calculator that has 3...
Create an ASP.Net Website using Visual Studio with C#: Create a simple calculator that has 3 text boxes: 2 of them to enter numbers, the 3rd one displays the results Create 4 buttons to add, subtract, multiply, and divide Prevent the user from entering text in the number fields Display a message indicating “cannot divide by” when the user click “/” and there is a zero the in the second box Create two additional buttons: - One to store data...
In Visual Studio in C#, you will create a simple calculator that performs addition, subtraction, multiplication,...
In Visual Studio in C#, you will create a simple calculator that performs addition, subtraction, multiplication, and division. Your program should request a numerical input from the user, followed by the operation to be performed, and the second number to complete the equation. The result should be displayed to the user after each equation is performed. For example, if the user performs 3+3, the program should display 6 as the result. The program should continue running so the user can...
C# ( asp.net ) 2019 Visual Studio I have a dropdown where you can select (...
C# ( asp.net ) 2019 Visual Studio I have a dropdown where you can select ( integer, string, date ) After selecting the desired dropdown option, user can input a list of inputs. For example; for integer: 2,5,7,9,1,3,4 And then , I have a 'sort' button Can you please help me with the code behind for sorting them( For integer, string, and date ) Thank you.
C# ( asp.net ) 2019 visual studio I have a dropdown option. If I choose "date"...
C# ( asp.net ) 2019 visual studio I have a dropdown option. If I choose "date" option, I get to enter list of dates like 02/08/1990, 06/14/1890 in (mm/dd/YYYY) format. How can I sort these dates in ascending order?. Can you provide me some code. Thank you
Using Visual Studio in C#; create a grading application for a class of ten students. The...
Using Visual Studio in C#; create a grading application for a class of ten students. The application should request the names of the students in the class. Students take three exams worth 100 points each in the class. The application should receive the grades for each student and calculate the student’s average exam grade. According to the average, the application should display the student’s name and the letter grade for the class using the grading scheme below. Grading Scheme: •...
create a C++ program using Visual Studio that could be used by a college to track...
create a C++ program using Visual Studio that could be used by a college to track its courses. In this program, create a CollegeCourse class includes fields representing department, course number, credit hours, and tuition. Create a child (sub class) class named LabCourse, that inherits all fields from the the CollegeCourse class, includes one more field that holds a lab fee charged in addition to the tuition. Create appropriate functions for these classes, and write a main() function that instantiates...
Android Studio (Java) I'm trying to create a simple calculator. I want to put out a...
Android Studio (Java) I'm trying to create a simple calculator. I want to put out a message if they try to divide by 0. I have this so far. What code should I put? divide.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (number1.getText().length() != 0 && number2.getText().length() != 0) { double n1= Double.parseDouble(number1.getText().toString()); double n2= Double.parseDouble(number2.getText().toString()); double res= n1 / n2; result.setText(String.valueOf(res)); } else { Toast.makeText(view.getContext(), "Please enter the numbers properly", Toast.LENGTH_SHORT).show(); } } });
Please use original C++ code for this. This is for visual studio. Program 5: Shipping Calculator...
Please use original C++ code for this. This is for visual studio. Program 5: Shipping Calculator The Speedy Shipping Company will ship packages based on how much they weigh and how far they are being sent. They will only ship small packages up to 10 pounds. You have been tasked with writing a program that will help Speedy Shipping determine how much to charge per delivery. The charges are based on each 500 miles shipped. Shipping charges are not pro-rated;...
Create a program using python that provides a simple calculator: Requires a login with a prompt...
Create a program using python that provides a simple calculator: Requires a login with a prompt for a username and a password prior to using the calculator If username and password are incorrect, the program should re-prompt to re-enter correct username and password Once logged in, the user should have access to the calculator and should have the ability for the following mathematical operators: Addition Subtraction Multiplication Division Square Root PI Exponents
Create a new “Area” project. Create a new Visual Studio Project and call it “Area”. This...
Create a new “Area” project. Create a new Visual Studio Project and call it “Area”. This project will be used to calculate the area of certain figures, like circles, squares and rectangles. So add a title to the Form. The Form Title should say “Area”. Also add 3 labels, 3 Buttons, 3 Textboxes and 3 RadioButtons. The 3 Buttons should be near the bottom of the Form and say “Calc Area”, “Clear” and “Exit”. Make sure to give all your...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT