T
Tony
Hello!
I use VS 2010 professional. I try to enter an example from a book that I
read but it doesn't work.
I have created a VB project and enter the code below in an aspx file.
The text say "To try this page out, open a browser and type in the URL,
appending the query string
?quantity=5&itemid=Item&unitPrice=54.
Nothing happen but according to the book it should display the following
<updateTotalRespone>
<discount>10 </discount>
<extPrice>243 </extPrice>
</updateTotalRespone>
I try to use the built in web server in Visual Studio.
So what is it that I have missed here ?
%@ Page Language="VB" AutoEventWireup="false"
CodeFile="updateTotal1.aspx.vb" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<script langauge="VB" runat="server">
Sub Page_Load(Src As Object, E As EventArgs)
Response.ContentType = "text/xml"
Dim quantity, unitPrice
Dim discount, extPrice
On Error Resume Next
quantity = Request.QueryString.Item("quantity")
unitPrice = Request.QueryString.Item("unitPrice")
discount = QuantityDiscount(quantity)
extPrice = (CDbl(quantity) * CDbl(unitPrice)) * (1 - (discount /
100))
If Err.Number <> 0 Then
Response.Write(ErrorXML())
Else
Response.Write(SuccessXML(discount, extPrice))
End If
End Sub
Function QuantityDiscount(quantity)
'For the sake of the example, just return a fixed amount
QuantityDiscount = 10
End Function
Function ErrorXML()
Dim sXML
sXML = "<Error><Reason>Invalid numbers </Reason></Error>"
ErrorXML = sXML
End Function
Function SuccessXML(sDiscount, sExtprice)
Dim sXML
sXML = "<updateTotalResponse>" & vbNewLine
sXML = sXML & " <discount>" & sDiscount & "</discount>" &
vbNewLine
sXML = sXML & " <extPrice>" & sExtprice & "</extPrice>" &
vbNewLine
sXML = sXML & " </updateTotalResponse>"
SuccessXML = sXML
End Function
</script>
</body>
</html>
//Tony
I use VS 2010 professional. I try to enter an example from a book that I
read but it doesn't work.
I have created a VB project and enter the code below in an aspx file.
The text say "To try this page out, open a browser and type in the URL,
appending the query string
?quantity=5&itemid=Item&unitPrice=54.
Nothing happen but according to the book it should display the following
<updateTotalRespone>
<discount>10 </discount>
<extPrice>243 </extPrice>
</updateTotalRespone>
I try to use the built in web server in Visual Studio.
So what is it that I have missed here ?
%@ Page Language="VB" AutoEventWireup="false"
CodeFile="updateTotal1.aspx.vb" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<script langauge="VB" runat="server">
Sub Page_Load(Src As Object, E As EventArgs)
Response.ContentType = "text/xml"
Dim quantity, unitPrice
Dim discount, extPrice
On Error Resume Next
quantity = Request.QueryString.Item("quantity")
unitPrice = Request.QueryString.Item("unitPrice")
discount = QuantityDiscount(quantity)
extPrice = (CDbl(quantity) * CDbl(unitPrice)) * (1 - (discount /
100))
If Err.Number <> 0 Then
Response.Write(ErrorXML())
Else
Response.Write(SuccessXML(discount, extPrice))
End If
End Sub
Function QuantityDiscount(quantity)
'For the sake of the example, just return a fixed amount
QuantityDiscount = 10
End Function
Function ErrorXML()
Dim sXML
sXML = "<Error><Reason>Invalid numbers </Reason></Error>"
ErrorXML = sXML
End Function
Function SuccessXML(sDiscount, sExtprice)
Dim sXML
sXML = "<updateTotalResponse>" & vbNewLine
sXML = sXML & " <discount>" & sDiscount & "</discount>" &
vbNewLine
sXML = sXML & " <extPrice>" & sExtprice & "</extPrice>" &
vbNewLine
sXML = sXML & " </updateTotalResponse>"
SuccessXML = sXML
End Function
</script>
</body>
</html>
//Tony