errors in asp code

H

hemdagem

<%
2. option explicit
3. '
4. set fs=CreateObject("Scripting.FileSystemObject")
5. set tfile=fs.CreateTextFile("c:\somefile.txt")
6. test = "Hello World!"
6. tfile.WriteLine(test)
7. '
8. response.write("<table>") & vbcrlf
9. '
10. for again = 1 to 50
11. for rep = 1 to 100
12. leftcolunn = rep
13. middlecolumn = sqr(rep) * lg(rep)
14. rightcolumn = again * rep
15. response.write("<tr>") & vbcrlf
16. response.write("<td>" + leftcolumn + </td>") &
vbcrlf
17. response.write("<td>" + middlecolumn + </td>") &
vbcrlf
18. response.write("<td>" + rightcolumn + </td>") &
vbcrlf
19. response.write("<tr>") & vbcrlf
20. next rep
21. next again
22. '
23. response.buffer = false
24. server.timeout = 10000
25.'
26. </script>

Hi i have to find atleast 5 errors think i found four:


1. leftcolunn should be spelt leftcolumn
2.no <style> tag
3.no %> close tag
4.no </table> close tag

help me out please urgent


and i have these tasks to do:

The following is piece of ASP code which has at least 5 fatal
errors - identify what these are and how they can be fixed.
B) Suggest a better way to achieve the functionality show in lines 10
to 21
C) When running this code you get a "permission denied" error for
line 5. Why is this caused and how could you resolve this issue.
D) Write additional ASP code that will send this table generated in
lines 10 to 21 as an HTML e-mail to an e-mail address entered into
an HTML form on the page.


Hemang
 
S

Slim

5
row needs end tag </tr>

6
set fs=Server.CreateObject("Scripting.FileSystemObject")
not
set fs=CreateObject("Scripting.FileSystemObject")

7
varaibles not declared, must be delcared if using option explicit

8
middlecolumn = sqr(rep) * lg(rep) what is lg()

9
set tfile=fs.CreateTextFile("c:\somefile.txt")
should have true to overwrite existing file, or page can only run once
set tfile=fs.CreateTextFile("c:\somefile.txt",true)


10
response.write("<td>" + leftcolumn + </td>") &

Use "&" not "+"

also these lines are unnesasary

response.buffer = false
server.timeout = 10000
 
B

Bob Barrows [MVP]

Slim said:
6
set fs=Server.CreateObject("Scripting.FileSystemObject")
not
set fs=CreateObject("Scripting.FileSystemObject")

Not true. This is purely optional. The vbscript version has been reported to
improve performance vs using the Server object's version. Purely anecdotal
but there it is. Using the vbscript version of createobject is not typically
a cause for errors.

http://blogs.msdn.com/ericlippert/archive/2004/06/01/145686.aspx
7
varaibles not declared, must be delcared if using option explicit

By declaring, Slim means to use a "dim" statement, as in:

dim again
8
middlecolumn = sqr(rep) * lg(rep) what is lg()

Slim is asking this question because vbscript has no builtin function called
lg(), and you do not seem to have created an array called lg()
10
response.write("<td>" + leftcolumn + </td>") &

Use "&" not "+"

Good coding practice, but usually not a cause of errors.
also these lines are unnesasary

response.buffer = false
server.timeout = 10000
Sure, the timeout is probably unnecessary, but maybe the buffer is not
needed on this page ...
 
M

Mike Brind

<%
2. option explicit
3. '
4. set fs=CreateObject("Scripting.FileSystemObject")
5. set tfile=fs.CreateTextFile("c:\somefile.txt")
6. test = "Hello World!"
6. tfile.WriteLine(test)
7. '
8. response.write("<table>") & vbcrlf
9. '
10. for again = 1 to 50
11. for rep = 1 to 100
12. leftcolunn = rep
13. middlecolumn = sqr(rep) * lg(rep)
14. rightcolumn = again * rep
15. response.write("<tr>") & vbcrlf
16. response.write("<td>" + leftcolumn + </td>") &
vbcrlf
17. response.write("<td>" + middlecolumn + </td>") &
vbcrlf
18. response.write("<td>" + rightcolumn + </td>") &
vbcrlf
19. response.write("<tr>") & vbcrlf
20. next rep
21. next again
22. '
23. response.buffer = false
24. server.timeout = 10000
25.'
26. </script>

Hi i have to find atleast 5 errors think i found four:


1. leftcolunn should be spelt leftcolumn
2.no <style> tag
3.no %> close tag
4.no </table> close tag

help me out please urgent


and i have these tasks to do:

The following is piece of ASP code which has at least 5 fatal
errors - identify what these are and how they can be fixed.
B) Suggest a better way to achieve the functionality show in lines 10
to 21
C) When running this code you get a "permission denied" error for
line 5. Why is this caused and how could you resolve this issue.
D) Write additional ASP code that will send this table generated in
lines 10 to 21 as an HTML e-mail to an e-mail address entered into
an HTML form on the page.


Hemang

The easiest way to identify errors is to run the code and see at which line
it falls over. Check the error message, fix it and then run it again. If
you don't understand what an error message means, copy it into google or
www.aspfaq.com, or even google groups.

Two of the errors you've hightlighted aren't fatal, but Slim has already
covered some others that are. "Fatal" means that the script will stop
running and return and error message to the browser. If it runs fine but
looks all messed up, that's the cause of faulty logic or html, not a fatal
error.

In addition, lines 20 and 21 will stop execution with an 'expected end of
statement' error. That syntax is fine for VB and VBA, but not for VBScript.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top