tomtom
2006-03-29, 19:08:00
Hi Leute,
Ich hab ein Problem...ich muss heute Abend noch ein kleines ASP .NET Programm fertig kriegen. Die Komplexität der Funktionalität lasst mal bitte außen vor ;)! Es geht um folgendes: Das ganze soll ein kleiner Rechner werden/sein dem man zwei Werte übergeben kann (value1 und value2) Über diese Werte soll man dann die 4 Grundrechnungsarten berechnen können. Die Werte (Eingaben sowie auch das Ergebnis) sollen in einer Session gespeichert werden:
Session("result") = Ergebnis
Session("value1") = eingegebener Wert1
Session("value2") = eingegebener Wert2
Folgende Probleme hab ich: Wie lese ich RadioButtons richtig aus, sodass ich dass der Methode doCalc übergeben kann? Krieg da immer nur "txtType is not declared". Des Weiteren weiß ich nicht mal, ob das mit der Session alles richtig ist, bin nämlich nicht in der Lage da irgendwas zu berechnen...
Muss dazu sagen, dass ich noch nie was mit ASP .NET machen musste und das nur ein kleiner Ausflug dahin sein sollte - wär super wenn mir schnell wer helfen könnte. Kann natürlich sein, dass ich kompletten Crap "programmiert" hab (ich geh ehrlich gesagt auch davon aus^^)...aber wär echt toll, wenn das heute noch hinhauen würde!
Hier mal der Code:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<script runat="server">
Sub Session_Start(ByVal Sender As Object, ByVal E As EventArgs)
Session("result") = 0
Session("value1") = txtValue1.Value
Session("value2") = txtValue2.Value
'Session.Item("result").ToString
End Sub
Sub Page_Load(ByVal Sender As Object, _
ByVal E As EventArgs)
If IsPostBack Then
Session("value1") = txtValue1.Value
Session("value2") = txtValue2.Value
doCalc(Session("value1"), Session("value2"), txtType.Value)
End If
End Sub
Function checkInput(ByRef value1 As Double, ByRef value2 As Double) As Boolean
If value1 <> 0 And value2 <> 0 Then
checkInput = True
Else
checkInput = False
End If
End Function
Sub add(ByVal value1 As Double, ByVal value2 As Double)
Dim result As Double
result = value1 + value2
Session("result") = result
Session("value1") = value1
Session("value2") = value2
End Sub
Sub subtract(ByVal value1 As Double, ByVal value2 As Double)
Dim result As Double
result = value1 - value2
Session("result") = result
Session("value1") = value1
Session("value2") = value2
End Sub
Sub mul(ByVal value1 As Double, ByVal value2 As Double)
Dim result As Double
result = value1 * value2
Session("result") = result
Session("value1") = value1
Session("value2") = value2
End Sub
Sub div(ByVal value1 As Double, ByVal value2 As Double)
Dim result As Double
If value2 > 0 Then result = value1 / value2
Session("result") = result
Session("value1") = value1
Session("value2") = value2
End Sub
Sub doCalc(ByVal value1 As Double, ByVal value2 As Double, ByVal type As String)
If checkInput(value1, value2) = True Then
Select Case (type)
Case "type1" : add(value1, value2)
Case "type2" : subtract(value1, value2)
Case "type3" : mul(value1, value2)
Case "type4" : div(value1, value2)
End Select
txtValue1.Value = Session("value1")
txtValue2.Value = Session("value2")
txtResult.Text = Session("result")
End If
End Sub
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<link rel="stylesheet" type="text/css" href="style.css" />
<title>Grundlagen der Diplomarbeit: Rechner - ASP .NET</title>
</head>
<body>
<div class="outborder">
<div class="display">
<asp:Label id="txtResult" Text="0" runat="server"/>
</div>
<form action="Default.aspx" method="post" id="form1" runat="server">
<div class="value1">
<input class="value" type="text" runat="server" id="txtValue1" value="0" />
</div>
<div class="value2">
<input class="value" type="text" runat="server" id="txtValue2" value="0" />
</div>
<div class="options">
<table>
<tr>
<td><asp:RadioButton id="type1" Checked="true" GroupName="txtType" Text="Addieren" runat="server"/></td>
</tr>
<tr>
<td><asp:RadioButton id="type2" Checked="false" GroupName="txtType" Text="Subtrahieren" runat="server"/></td>
</tr>
<tr>
<td><asp:RadioButton id="type3" Checked="false" GroupName="txtType" Text="Multiplizieren" runat="server"/></td>
</tr>
<tr>
<td><asp:RadioButton id="type4" Checked="false" GroupName="txtType" Text="Dividieren" runat="server"/></td>
</tr>
</table>
</div>
<div class="options2">
<table>
<tr>
<td><input class="optionsbutton" runat="server" type="submit" value="=" /></td>
</tr>
</table>
</div>
</form>
</div>
</body>
</html>
Big thx im Voraus!
lg, t2k3
Ich hab ein Problem...ich muss heute Abend noch ein kleines ASP .NET Programm fertig kriegen. Die Komplexität der Funktionalität lasst mal bitte außen vor ;)! Es geht um folgendes: Das ganze soll ein kleiner Rechner werden/sein dem man zwei Werte übergeben kann (value1 und value2) Über diese Werte soll man dann die 4 Grundrechnungsarten berechnen können. Die Werte (Eingaben sowie auch das Ergebnis) sollen in einer Session gespeichert werden:
Session("result") = Ergebnis
Session("value1") = eingegebener Wert1
Session("value2") = eingegebener Wert2
Folgende Probleme hab ich: Wie lese ich RadioButtons richtig aus, sodass ich dass der Methode doCalc übergeben kann? Krieg da immer nur "txtType is not declared". Des Weiteren weiß ich nicht mal, ob das mit der Session alles richtig ist, bin nämlich nicht in der Lage da irgendwas zu berechnen...
Muss dazu sagen, dass ich noch nie was mit ASP .NET machen musste und das nur ein kleiner Ausflug dahin sein sollte - wär super wenn mir schnell wer helfen könnte. Kann natürlich sein, dass ich kompletten Crap "programmiert" hab (ich geh ehrlich gesagt auch davon aus^^)...aber wär echt toll, wenn das heute noch hinhauen würde!
Hier mal der Code:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<script runat="server">
Sub Session_Start(ByVal Sender As Object, ByVal E As EventArgs)
Session("result") = 0
Session("value1") = txtValue1.Value
Session("value2") = txtValue2.Value
'Session.Item("result").ToString
End Sub
Sub Page_Load(ByVal Sender As Object, _
ByVal E As EventArgs)
If IsPostBack Then
Session("value1") = txtValue1.Value
Session("value2") = txtValue2.Value
doCalc(Session("value1"), Session("value2"), txtType.Value)
End If
End Sub
Function checkInput(ByRef value1 As Double, ByRef value2 As Double) As Boolean
If value1 <> 0 And value2 <> 0 Then
checkInput = True
Else
checkInput = False
End If
End Function
Sub add(ByVal value1 As Double, ByVal value2 As Double)
Dim result As Double
result = value1 + value2
Session("result") = result
Session("value1") = value1
Session("value2") = value2
End Sub
Sub subtract(ByVal value1 As Double, ByVal value2 As Double)
Dim result As Double
result = value1 - value2
Session("result") = result
Session("value1") = value1
Session("value2") = value2
End Sub
Sub mul(ByVal value1 As Double, ByVal value2 As Double)
Dim result As Double
result = value1 * value2
Session("result") = result
Session("value1") = value1
Session("value2") = value2
End Sub
Sub div(ByVal value1 As Double, ByVal value2 As Double)
Dim result As Double
If value2 > 0 Then result = value1 / value2
Session("result") = result
Session("value1") = value1
Session("value2") = value2
End Sub
Sub doCalc(ByVal value1 As Double, ByVal value2 As Double, ByVal type As String)
If checkInput(value1, value2) = True Then
Select Case (type)
Case "type1" : add(value1, value2)
Case "type2" : subtract(value1, value2)
Case "type3" : mul(value1, value2)
Case "type4" : div(value1, value2)
End Select
txtValue1.Value = Session("value1")
txtValue2.Value = Session("value2")
txtResult.Text = Session("result")
End If
End Sub
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<link rel="stylesheet" type="text/css" href="style.css" />
<title>Grundlagen der Diplomarbeit: Rechner - ASP .NET</title>
</head>
<body>
<div class="outborder">
<div class="display">
<asp:Label id="txtResult" Text="0" runat="server"/>
</div>
<form action="Default.aspx" method="post" id="form1" runat="server">
<div class="value1">
<input class="value" type="text" runat="server" id="txtValue1" value="0" />
</div>
<div class="value2">
<input class="value" type="text" runat="server" id="txtValue2" value="0" />
</div>
<div class="options">
<table>
<tr>
<td><asp:RadioButton id="type1" Checked="true" GroupName="txtType" Text="Addieren" runat="server"/></td>
</tr>
<tr>
<td><asp:RadioButton id="type2" Checked="false" GroupName="txtType" Text="Subtrahieren" runat="server"/></td>
</tr>
<tr>
<td><asp:RadioButton id="type3" Checked="false" GroupName="txtType" Text="Multiplizieren" runat="server"/></td>
</tr>
<tr>
<td><asp:RadioButton id="type4" Checked="false" GroupName="txtType" Text="Dividieren" runat="server"/></td>
</tr>
</table>
</div>
<div class="options2">
<table>
<tr>
<td><input class="optionsbutton" runat="server" type="submit" value="=" /></td>
</tr>
</table>
</div>
</form>
</div>
</body>
</html>
Big thx im Voraus!
lg, t2k3