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...
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...
For this IP, you will create a very simple drawing app using Android Studio. The purpose...
For this IP, you will create a very simple drawing app using Android Studio. The purpose of this assignment is to give you more building blocks to use when programming apps. For full credit for this assignment, you should complete the following: Create a menu and display menu items on the app bar Detect when the user touches the screen and moves a finger Be able to change the color and width of a line Be able to save an...
In visual Studio C++ Create a program that uses a for loop to input the high...
In visual Studio C++ Create a program that uses a for loop to input the high temperature, and low temperature for each day of the week. The high and low will be placed into two elements of the array. For each loop the high and low will be placed into the next set of elements of the array. After the temps for all seven days have been entered into the array, a for loop will be used to pull out...
Introduction to Java Programing Using Loop Create a simple calculator program using loop Ask user to...
Introduction to Java Programing Using Loop Create a simple calculator program using loop Ask user to input two numbers using scanner class Print the instruction of the menu for the calculator program Ask user to press 0 to Quit Ask user to press 1 to Add Ask user to press 2 to Substract Ask user to press 3 to Multiply Ask user to press 4 to Divide Perform correct calcuation based on user inputs and print the result Print error...
Create a C# .NET Core Console project in Visual Studio. (This is the same kind of...
Create a C# .NET Core Console project in Visual Studio. (This is the same kind of project we have been doing all semester.) Do all of the following in the Program class. You do not need to add any other classes to this project. 2. If it exists, remove the Console.WriteLine(“Hello World!”); line that Visual Studio created in the Program class. 3. At the very top of the Program.cs page you should see using System; On the empty line below...
VISUAL STUDIO CODE Use a for loop for to create "password". Request the password at least...
VISUAL STUDIO CODE Use a for loop for to create "password". Request the password at least 3 times. If the password is 12345, the procedure ends, if the correct password entered, close excel saving changes. THANKS
In c# I need to create a simple payroll management system using visual basic and GUI....
In c# I need to create a simple payroll management system using visual basic and GUI. I also need to connect to SQL database. It needs a log in screen, inside the login screen it needs another screen to enter or edit employee information. It needs somewhere to enter hours worked for that specific employee, and another screen that can access reports.
Create a Visual Studio console project using c++ void lowerToUpper(std::string & sentence) that iterates over all...
Create a Visual Studio console project using c++ void lowerToUpper(std::string & sentence) that iterates over all characters in the sentence argument. Any lowercase letter should be converted to uppercase. This can be done by including <cctype> and testing each character in sentence with the islower() function. If islower(sentence[i]) returns true then sentence[i] should be replaced with toupper(sentence[i]). The main() function should assign "Hello how are you doing?" to sentence, call lowerToUpper(sentence), and use an if statement to check the new...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT