Saturday, March 24, 2012

Trouble viewing my coding. Please help newbie.

Hello here is the code that I have made. It is a simple file:
________________________________________________

dim Grade As Integer
Dim LetterGrade As String
Randomize
Grade = Int(Rnd * 100) + 1 ' Random number between 1 and 100
%>

Your grade is .
Case Is >= 90
LetterGrade = "A" %>

You got an A! Congratulations.


= 80
LetterGrade = "B" %>

You got a B. Good job.


= 70
LetterGrade = "C" %>

You got a C. Not bad.


= 60
LetterGrade = "D" %>

You got a D. Try harder next time.


LetterGrade = "F" %>

You failed. I'm sorry.

________________________________________________
It should generate a random grade and display a message according to that grade. I saved the file to my wwwroot folder inside inetpub. When I open the file with explorer it looks like this:

http://electronicbooking.com/untitled.JPG

WHy is that. Why is it not executing the vb.net code? THanks for your help!

Greg

dim>Hi, welcome to the ASP.NET Forums!

Is that an exact copy and paste of your code? If so, there seem to be a lot of syntax errors. Your code should look more like this:

<%@.Page Language="VB"%
<script runat="server">
Sub Page_Load (s As object, e As EventArgs)

Dim Grade As Integer
Dim LetterGrade As String
Dim GradeMessage As String

Randomize
Grade = Int(Rnd * 100) + 1 ' Random number between 1 and 100
Select Case Grade
Case Is >= 90
LetterGrade = "A"
GradeMessage = "You got an A! Congratulations."
Case Is >= 80
LetterGrade = "B"
GradeMessage = "You got a B. Good job."
Case Is >= 70
LetterGrade = "C"
GradeMessage = "You got a C. Not bad."
Case Is >= 60
LetterGrade = "D"
GradeMessage = "You got a D. Try harder next time."
Case Else
LetterGrade = "F"
GradeMessage = "You failed. I'm sorry."
End Select
myResult.Text = "Your Grade is " & LetterGrade & "<br />" & GradeMessage
End Sub
</script>
<html>
<head>
<title>Test Grades</title>
</head
<body>
<form id="form1" runat="server">
<asp:Label ID="myResult" runat="server" />
</form>
</body>
</html>
Hey, thanks for the quick reply. I cant believe that, i paid $30 for a bigginers book to asp.net and the coding is wrong?? I tried the code you gave me and now it is a blank page. In the bottom left hand corner next to the word done there is a symbole with a white page behind a yellow sign. THanks again for the help!

Greg

grogo21 wrote:

Hey, thanks for the quick reply. I cant believethat, i paid $30 for a bigginers book to asp.net and the coding iswrong?? I tried the code you gave me and now it is a blank page. In thebottom left hand corner next to the word done there is a symbole with awhite page behind a yellow sign. THanks again for the help!Greg


You need to be careful when posting code into the text editor here; it is usually a good idea to paste it into Notepad first. Always click on the Preview tab before posting. If you look at whatyou posted, you will see that it does not really represent your code. As a moderator, I just now went into your post to see what you actuallypasted, and it is more like this:

<%@.Page Explicit="True" Language="VB" Debug="True" %>
<%
Dim Grade As Integer
Dim LetterGrade As String
Randomize Grade = Int(Rnd * 100) + 1 ' Random number between 1 and 100 %
Your grade is <%=Grade%>.
<% Select Case Grade Case Is >= 90 LetterGrade = "A" %
You got an A! Congratulations.
<% Case Is >= 80 LetterGrade = "B" %
You got a B. Good job.
<% Case Is >= 70 LetterGrade = "C" %
You got a C. Not bad.
<% Case Is >= 60 LetterGrade = "D" %
You got a D. Try harder next time.
<% Case Else LetterGrade = "F" %
You failed. I'm sorry.
<% End Select %

So, there aren't truly syntax errors after all. I have no idea which book you bought, and I am hesitant to speakdisparagingly not knowing more, but I can tell you that if that is thecode from the book, they are using more of an old school approach,reminiscent of the old ASP 3.0 days. An excellent book for beginnersis ASP.NET Unleashed, Second Edition, by Stephen Walther. (And ASP.NET2.0 version should be out in about 2 months I believe.)

Now, I suspect that you do not have ASP.NET running on your machine. Is it downloaded and installed? What are you using to create your testpages? What operating system is running on your machine?

I believe the symbol in the left-hand corner is a JavaScript errortelling you something is wrong on the page. If you double click on theyellow sign you should be able to see the error mesasge.


http://electronicbooking.com/untitled.JPG. you mean windows explored? Asp.net pages have to be served up by a web server, wither IIS or the vwd express development server. Try opening the page in a browser. Also if you save it as untitled.jpg that extention says its an image file fot an ASP.net file. Asp.net webforms use an extention of aspx

0 comments:

Post a Comment