<%@ Page Language="VB" Debug="true" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
uitkomst.Text = "..."
Dim x1 = 0, x2 = 0
Dim bew
If getal1.Text = "" And getal2.Text = "" Then
x1 = 0
x2 = 0
Else
If getal1.Text <> "" And getal2.Text = "" Then
x1 = Convert.ToDouble(getal1.Text)
x2 = 0
Else
If getal1.Text = "" And getal2.Text <> "" Then
uitkomst.Text = "Het eerste vak moet ingevuld worden"
Else
If getal1.Text <> "" And getal2.Text <> "" Then
x1 = Convert.ToDouble(getal1.Text)
x2 = Convert.ToDouble(getal2.Text)
End If
End If
End If
End If
bew = bewerking.SelectedItem.ToString
If bew = "+" Then
uitkomst.Text = "De som is " & x1 + x2
End If
If bew = "-" Then
uitkomst.Text = "Het verschil is " & x1 - x2
End If
If bew = "*" Then
uitkomst.Text = "Het product is " & x1 * x2
End If
If bew = "/" Then
If x2 = 0 Then
uitkomst.Text = "Geen deling door 0!"
Else
uitkomst.Text = "Het quotiënt is " & Math.Round(x1 / x2, 3)
End If
End If
If bew = "%" Then
Dim rest As Integer
Dim deling As Integer = System.Math.DivRem(x1, x2, rest)
uitkomst.Text = (String.Format("Deling met rest: {0}, met als rest {1}", deling.ToString(), rest.ToString()))
End If
If bew = "x²" Then
uitkomst.Text = "Het kwadraat is " & x1 ^ 2
End If
If bew = "x^y" Then
uitkomst.Text = x1 & " tot de " & x2 & "e macht is " & Math.Pow(x1, x2)
End If
If bew = "x^(1/2)" Then
uitkomst.Text = "De vierkantswortel is " & Math.Round(Math.Sqrt(x1), 3)
End If
If bew = "x!" Then
If x1 < 13 Then
Dim i As Integer = x1
Dim res As Integer = x1
Do
res = res * (i - 1)
i = i - 1
Loop While i > 1
uitkomst.Text = "De faculteit van " & x1 & " is " & res
Else
uitkomst.Text = "Getal mag voor x! maximum 12 zijn"
End If
End If
bewerking.SelectedValue = ""
End Sub
Sub pi_Click(ByVal sender As Object, ByVal e As EventArgs) Handles pi1.Click
getal1.Text = Math.PI
End Sub
Sub pi2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles pi2.Click
getal2.Text = Math.PI
End Sub
Sub wissen_Click(ByVal sender As Object, ByVal e As EventArgs) Handles wissen.Click
getal1.Text = ""
getal2.Text = ""
bewerking.SelectedValue = ""
uitkomst.Text = "..."
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Rekenmachine in ASP.NET</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<center>
<br /><br />
<h3><u>Rekenmachine in ASP.NET</u></h3><br />
<table>
<tr>
<td align="right">Eerste getal: </td><td><asp:TextBox ID="getal1" runat="server" Width="100" /> <asp:Button ID="pi1" runat="server" Text="Pi" /></td>
</tr>
<tr>
<td align="right">Tweede getal: </td><td><asp:TextBox ID="getal2" runat="server" Width="100" /> <asp:Button ID="pi2" runat="server" Text="Pi" /></td>
</tr>
<tr>
<td align="right">
Bewerking:
</td>
<td align="left">
<asp:DropDownList ID="bewerking" runat="server" AutoPostBack="true" >
<asp:ListItem></asp:ListItem>
<asp:ListItem>+</asp:ListItem>
<asp:ListItem>-</asp:ListItem>
<asp:ListItem>*</asp:ListItem>
<asp:ListItem>/</asp:ListItem>
<asp:ListItem>%</asp:ListItem>
<asp:ListItem>x²</asp:ListItem>
<asp:ListItem>x^y</asp:ListItem>
<asp:ListItem>x^(1/2)</asp:ListItem>
<asp:ListItem>x!</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
</table>
<br />
<table width="275">
<tr>
<td>
<fieldset>
<legend>Resultaat</legend>
<asp:Label ID="uitkomst" runat="server" />
</fieldset>
</td>
</tr>
</table>
<asp:Button ID="wissen" runat="server" Text="Alles wissen" />
</center>
</div>
</form>
</body>
</html>