I'm trying to find a way how to get the code line number in Classic ASP
<%
Response.Write "Hello world!<br>"
Response.Write getThisLineNumber() & "<br>"
Response.Write "Goodbye world."
%>
Expected output
Hello world.
3
Goodbye world.
getThisLineNumber() is a fictional function doing what I'm looking for.
I temporarily solved my problem by
<%
Response.Write "Hello world!<br>"
Response.Write "3<br>"
Response.Write "Goodbye world."
%>
but when i add a new line after "Hello world." (2nd line), then I manually must change
Response.Write "3<br>"
to
Response.Write "4<br>"
Classic ASP does not support such a feature, it's something like Reflection in .NET.
The closer thing you can do is get line number when an error happens in Err object, this way: Err.Line.
If you want to profile an asp page, maybe ASP Profiler can help you: ASP Profiler
Related
i'm trying to do an do while with this code:
<%
dim i
i=0
Do While i < 19
response.Write "<th>" & data1.standing.[i].position & "</th>"
i=i+1
Loop
%>
this come from a api call, is a json response, and data1.standing.[in].position is the way to extract the position of a soccer team: url :link
but this section [i] don't iterate.
any clue?
sorry for the bad english.
Looking at your code I suspect you're actually trying to use JScript, not VBScript as I assumed.
An example of how to gather the JSON string into a variable in VBScript:
dim objXML
Set objXML = Server.CreateObject("MSXML2.ServerXMLHTTP")
objXML.open "GET", "http://api.football- data.org/v1/competitions/398/leagueTable", False
objXML.send
Response.Write objXML.responseText
Take a look at this post for an excellent example of how to do what you're looking for. Any good libraries for parsing JSON in Classic ASP?
You can use my code to GET the string, then the link to parse and use it.
I found this on a project I'm working on:
<% If Session("VALUE1") <> "" Then %>
document.forms[0].action= "<%=Session("VALUE1")%>";
<% Else %>
document.forms[0].action="NewPage.aspx"
<% End If %>
When I single step through this starting at the top line, the code skips over the If Session("VALUE1") but also skips over the Else as well. How is this possible?
Inside both the If and Else blocks, there's no actual server code, only markup (which happens to be javascript). Since there's nothing to execute, your debugger doesn't have anything to stop at. So it's not actually skipping both of them.
If you look at the rendered output, one of the two will end up on the page.
The code isn't skipped, it's just that you don't see the actual code that is executed.
The code that is generated for that markup when the page is compiled looks something like this:
If Session("VALUE1") <> "" Then
Response.Write(" document.forms[0].action= """)
Response.Write(Session("VALUE1"))
Response.Write(""";")
Else
Response.Write(" document.forms[0].action=""NewPage.aspx""")
End If
As the Response.Write statements are generated and has no corresponding statements in the source code, it will look like they are skipped when you single step through the code.
I have an asp page that displays an online form after validating a user. I'm using Response.Write "form goes here" However, the form is very long (100+ lines).
Is there a way I can do Response.Write with multi-line html? I want to do something like this:
<%
If rs.rcount > 0 then
response.write "
<form>
<input type="text" id="inputEmail">
</form>"
End if
%>
Many thanks,
Use a code block, not response.write.
<%
...your VB ....
if a=b then
%>
<h1> HTML GOES HERE</h1>
<form>
<input type="text" id="inputEmail">
</form>
<%
end if
... more VB code
%>
You've got a couple of options, which one you pick depends on a few things...
(1) You can do as Diodeus suggested, and use a code block:
If rs.count > 0 Then
%>
<form>
<input type="text" id="etc" />
</form>
<%
End If
(2) You can do as Yuriy Galanter suggested, and build your form through string concatenation:
Dim sHTML;
sHTML = "<form>"
sHTML = sHTML & "<input type="text" id="etc" />"
'... etc.'
sHTML = "</form>"
If rs.rcount > 0 Then
Response.Write sHTML
End If
(3) You can do as you were initially thinking, writing out a line or three at a time:
If rs.rcount > 0 Then
Response.Write "<form>"
Response.Write "<input type="text" id="etc" />" & _
"<input type="text" id="other" />"
'The underscore above indicates that the string/command/etc. continues on the next line, whitespace is ignored.'
Response.Write "</form>"
End If
(4) You can mix and match any combination of the above
The benefit of option 1 is it's fairly fast, easy to edit, and simple to implement if you've already got the HTML ready to go.
The benefit of option 2 is you don't have to worry about context switching (not so much an issue in ASP 3, but it's something you'll see mentioned if you read and research enough), and it's (in my opinion) easier to insert variables if there are portions of your form that may change based on other business logic (or if you think that will be a need in the near future)
The benefit of option 3 is it's (again, my opinion) easier to conditionally show/hide/alter parts of the form depending on business logic (doesn't sound like an issue for you per se, but it's worth keeping in mind.)
Depending on your situation, you may find the best approach is some mix of the above. Just keep in mind that the more string concatenation you do, the worse your memory management will get.
There are also some libraries out there (like ASP-Ajaxed - full disclosure, I recently took over the project. Still working on rebuilding an official website) with templates and better managed string concatenation. Adding something like this after the fact isn't always easy, and may be overkill if you're just modifying an existing project (vs. creating a new project).
You can build your form in steps in a variable, e.g.
Dim sHTML;
sHTML = "<form>"
sHTML = sHTML & "<p><input type=""text"" id=""inputEmail""></p>"
'... etc.
Response.Write sHTML
Use HTML tags such as <br/> or <p></p> to place input elements at new lines.
If you're using ASP.NET/VB.NET you can use StringBuilder, which is much more efficient to construct dynamic strings
I'm having some trouble reading the ASP.NET cookie from a Classic ASP file. Here is the code i'm using:
First off, I have the ASP.NET site setup in IIS. I setup an Application in the ASP.NET site and directed it to another folder in inetpub. This Application is called '/classicasp' because its all classic asp inside that application.
In the .aspx file, it is executing this code:
Response.Cookies["testcookie"].Path = "/classicasp";
Response.Cookies["testcookie"].Value = "test";
In the .asp file, it is executing this code:
<%
for each cookie in Request.Cookies
Response.Write( cookie & "=" & Request.Cookies(cookie) & "Path:" &
"<br>")
next
%>
But the .asp page is empty, there are no results displayed on the page from this For Next statement.. Any help on why this is happening? I think i followed instructions and am doing this how its supposed to be, but i guess not..
try
dim x,y
for each x in Request.Cookies
response.write("<p>")
if Request.Cookies(x).HasKeys then
for each y in Request.Cookies(x)
response.write(x & ":" & y & "=" & Request.Cookies(x)(y))
response.write("<br />")
next
else
Response.Write(x & "=" & Request.Cookies(x) & "<br />")
end if
response.write "</p>"
next
I think this is what you are looking for:
Updating ASP cookie from ASP.NET (vice versa)
I am working on an old asp project. I am new in project. My question is,
I required to execute the certain number of pages in a specific time but when I put in a loop to execute the page for certain pattern it execute only one pattern and shows time out expired problem. Though I searched in net what ever answer I get it will not fulfill my requirement. So my team lead said we have to find out some thing that can execute my page for 3 min each then it call back freshly. Is there any method is there in asp. as I am new in asp. as it possible or share some idea.
I want to execute for each pattern. Here is my simple code.
dim arrList()
dim mySQL,x,strPtrn
mySQL=""
x=0
strPtrn=""
mySQL="select distinct(pattern_no) from pattern_master where std between (dateadd(hh,8,getdate())) and (dateadd(hh,11,getdate()))"
set rstptrnmst= conn.Execute(mySQL)
do until rstptrnmst.EOF
for each ptrn in rstptrnmst.Fields
' Response.Write(x.name)
'Response.Write(" = ")
'Response.Write(x.value & "<br />")
ReDim Preserve arrList(x)
arrList(x)=ptrn.value
x=x+1
next
Response.Write("<br />")
rstptrnmst.MoveNext
loop
rstptrnmst.close
conn.close
'for each ptrn in arrList
'response.Write("<br>" & ptrn)
'next
for each ptrn in arrList
Session("pattern")=ptrn
server.Execute("processFNO.asp")
Session("pattern")=""
response.write("The first pattern " & ptrn & "<br />")
next
'Response.Redirect("processFNO.asp?fno="&arrList(0))
%>
So I want execute that page for each pattern. How can I? For each pattern it take 3 min(approx).any idea?
thanks for advance.
If your script is going to take that long to run you will need to set the script timeout option to cater for that:
<%
Server.ScriptTimeout = 180
%>
The timeout is set in seconds, with the default being 90. You should set this at the very top of your page.
More information about timeouts here: How do I increase timeout values