Question: In VB.NET I need to Create a new WEB SITE with the following:- Create a webpage that contains server side directives, code declaration blocks, includes
In VB.NET I need to Create a new WEB SITE with the following:-
- Create a webpage that contains server side directives, code declaration blocks, includes and controls.
- Create a simple calculator the contains four labels, three textboxes, six buttons and a list box:
- The first label = enter first number
- The second label= enter second number
- The third label = should display the result
- Four of the buttons should be "+", "-", "*", "/"
- The result textbox should be read only
- The startup page must be named index.
- Display a message indicating cannot divide by when the user click / and there is a zero the in the second box
- Prevent the user from entering text in the number fields
- Create the other two buttons
- store data - The store data will store the results into array
- display data - The display data will display the contents of the array (use 10 for the array size)
I need some help with steps 10 & 11 on the server side.
Heres what I have so far for the VB.NET website and code behind:
Index.aspx:
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Index.aspx.vb" Inherits="Calculator.Index" %>
Index.aspx.vb:
Option Explicit On
Option Strict On
Option Infer Off
Public Class Index
Inherits System.Web.UI.Page
'Declares the variables
Dim dec1stNum As Decimal
Dim dec2ndNum As Decimal
Dim decResult As Decimal
Dim count As Integer = 0
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click
'Accepts input from txt1stNum & txt2ndNum
Decimal.TryParse(txt1stNum.Text, dec1stNum)
Decimal.TryParse(txt2ndNum.Text, dec2ndNum)
'Adds the 1st & 2nd numbers & displays the results
decResult = dec1stNum + dec2ndNum
txtResult.Text = dec1stNum & " + " & dec2ndNum & " = " & decResult
End Sub
Protected Sub btnSubtract_Click(sender As Object, e As EventArgs) Handles btnSubtract.Click
'Accepts input from txt1stNum & txt2ndNum
Decimal.TryParse(txt1stNum.Text, dec1stNum)
Decimal.TryParse(txt2ndNum.Text, dec2ndNum)
'Subtracts the 2nd number from the 1st number & displays the results
decResult = dec1stNum - dec2ndNum
txtResult.Text = dec1stNum & " - " & dec2ndNum & " = " & decResult
End Sub
Protected Sub btnMultiply_Click(sender As Object, e As EventArgs) Handles btnMultiply.Click
'Accepts input from txt1stNum & txt2ndNum
Decimal.TryParse(txt1stNum.Text, dec1stNum)
Decimal.TryParse(txt2ndNum.Text, dec2ndNum)
'Multiplies the 1st & 2nd numbers & displays the results
decResult = dec1stNum * dec2ndNum
txtResult.Text = dec1stNum & " X " & dec2ndNum & " = " & decResult
End Sub
Protected Sub btnDivide_Click(sender As Object, e As EventArgs) Handles btnDivide.Click
'Accepts input from txt1stNum & txt2ndNum
Decimal.TryParse(txt1stNum.Text, dec1stNum)
Decimal.TryParse(txt2ndNum.Text, dec2ndNum)
decResult = dec1stNum / dec2ndNum
'Displays a message box if the 2nd number entered is a 0
'If the 2nd number is not a 0, divides the 1st number by the 2nd number & displays the results
If dec2ndNum = 0 Then
MsgBox("cannot divide by 0")
txt2ndNum.Text = String.Empty
txt2ndNum.Focus()
Else
txtResult.Text = dec1stNum & " / " & dec2ndNum & " = " & decResult
End If
End Sub
Private Sub btnStoreData_Click(sender As System.Object, e As System.EventArgs) Handles btnStoreData.Click
Dim PrevOps(9) As String
Console.WriteLine(txtResult.Text)
Console.ReadKey()
End Sub
Private Sub btnDisplayData_Click(sender As System.Object, e As System.EventArgs) Handles btnDisplayData.Click
'Reads the Prevous Operations from the PrevOps text file and displays them in the list box
'Declares the variables
Dim inFile As IO.StreamReader
Dim strOperation As String
'Clears the previous PrevOps from the list box
lstPrevOps.Items.Clear()
'Determine wether the file exists
If IO.File.Exists("DisplayData.txt") Then
'Opens the file for input if it exists
inFile = IO.File.OpenText("DisplayData.txt")
'Processes the loop instructions until the end of the file
Do Until inFile.Peek = -1
'Reads the operation
strOperation = inFile.ReadLine
'Adds the operation to the list box
lstPrevOps.Items.Add(strOperation)
Loop
'Closes the file
inFile.Close()
End If
End Sub
End Class
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
