Log in

View Full Version : ASP Homework Help



Jeff
08-30-2008, 02:53 AM
Guys, I need some help! Here is the assignment -




Students at a certain University pay $90.00 per credit hour for all credit hours less than 12. If they enroll in 12 or more credit hours, thus becoming a full-time student, they pay a flat rate of $1100.00. All full-time students pay a $100.00 technology fee, and a $125.00 debt service fee. Students who are dependents of employees receive a 50-percent reduction on their basic fees but not on the additional fees.
Design an ASP.NET web page that accepts the number of credit hours and a Yes/No answer as to whether the student is a dependent and displays all fees separately and the total amount of fees due with appropriate labels. Include a printed message to those who receive a reduction in fees.
Include a CALCULATE button and a CLEAR button
Here is my code

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.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>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
Number of credit hours
<asp:TextBox ID="CreditHours" runat="server" Height="23px" Width="33px"></asp:TextBox>
<div>

Are you a dependant student?
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem>Yes</asp:ListItem>
<asp:ListItem>No</asp:ListItem>
</asp:DropDownList>

</div>
<asp:Button ID="Calculate" runat="server" Text="Calculate"/>
<asp:Button ID="Clear" runat="server" Text="Clear" />
<br />
<asp:Label ID="Label1" runat="server"></asp:Label><p>
</p>
</form>
</body>
</html>



Partial Class _Default
Inherits System.Web.UI.Page


Protected Sub Calculate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Calculate.Click
Dim tuition As Integer
Dim totalfees As Integer
Dim hours As Integer
Dim techfee = 100
Dim debtfee = 250
Dim Label1



hours = CInt(CreditHours.Text)
tuition = 1100
If hours < 12 Then
tuition = hours * 90
End If
If DropDownList1.SelectedValue = "Yes" Then
tuition = tuition * 0.5

End If
totalfees = tuition + techfee + debtfee
Document.write("Technical Fees: $100")
Document.write("Debt Services Fee: 250")
Document.write("Total Fees and Tuition: " & totalfees.ToString)
Label1.Text = "Total tuition and fees: " & totalfees.ToString




End Sub
End Class

Jeff
08-30-2008, 02:14 PM
I guess I should have explained that whenever I debug the code I receive errors that "Name 'Document' is not declared".

But I'm trying to use document.write so I don't understand how I would declare this.

Please help!

NeoGen
09-01-2008, 12:06 AM
Hiya Jeff

I just looked at your code, tried out a little something here and indeed it seems Document.write is not part of Visual Basic. ASP.Net works with Visual Basic or C#.
I looked up the "Document.write" on google, and it appeared links about javascript.
example: http://javascript.about.com/library/blwrite.htm

What are you trying to do with the Document.write? From what that page says, it seems that in javascript you use that command to write out text to the html page. I think that can't be done in ASP.Net. This is all object oriented now, so you have to place controls to receive the text (Like that Label1 that you use in the end).

In Visual Studio, for debugging purposes you can use this:
System.Diagnostics.Debug.Write
And the text that you write with that shows up on the "Immediate Window", sometimes along with other debug messages from Visual Studio.

Jeff
09-01-2008, 02:38 PM
NeoGen,

Thanks for helping me out. I could have swore that our professor used document.write to write as html. Here is a link I found, though not from my school. http://cisb.marin.edu/mike/C110VBlabs/VBScriptRef.htm


Im trying to program it so that when a user presses the calculate button, it calculates the tuition (which I believe I've done that correct), but it must also print out a list of fees.

The assignment mentions using labels, so I may try it that way instead.

Any advice?

NeoGen
09-01-2008, 08:25 PM
Ah... I see. :) You were trying to code in Visual Basic Script, not Visual Basic .NET (.NET is more widely used in ASP.NET)

That does work indeed, but I'm not used to it. You get to mess up directly with the html of the page.

On Visual Studio you can work with that using the controls on the "HTML" section of the ToolBox. Some of them are "Input (Button)", "Input (Reset)", "Input (Text)"... etc... Once you drag one of those into the designer you can work with it in scripting languages, vbscript and javascript.

To test I created a simple ASP.NET page, dragged an "Input (Button)" onto it, and double clicked it to create the event "hook" and function header

This is the "hook" for calling the click event of the button:


<inputid="Button1"type="button"value="button"onclick="return Button1_onclick()"/>


And this is a sample code for using the document.write in vbscript


<scriptlanguage="vbscript"type="text/vbscript">
function Button1_onclick()
document.write("This is a test.")
end function
</script>


For some reason the default scripting language here was javascript, I just had to change that first line to "vbscript" and rewrite the header of the function as it shows.
After that I put it running, and a blank webpage with a button showed up to me. I clicked it and the button disappeared, and the text showed up on the page.

NeoGen
09-01-2008, 08:53 PM
Jeff... I got your PM a while ago. Don't know if you got my reply, but I'm on FlashChat.
Pop in when you can. I'm there. :)