Ask Question Forum:
Model Library:2025-02-08:A.I. model is online auto reply
C
O
M
P
U
T
E
R
2
8
Show
#
ASK
RECENT
←
- Underline
- Bold
- Italic
- Indent
- Step
- Bullet
- Quote
- Cut
- Copy
- Paste
- Table
- Spelling
- Find & Replace
- Undo
- Redo
- Link
- Attach
- Clear
- Code
Below area will not be traslated by Google,you can input code or other languages
Hint:If find spelling error, You need to correct it,1 by 1 or ignore it (code area won't be checked).
X-position of the mouse cursor
Y-position of the mouse cursor
Y-position of the mouse cursor
Testcursor
caretPos
Attachment:===
Asked by rwniceing
at 2024-08-26 03:57:24
Point:500 Replies:3 POST_ID:829202USER_ID:12079
Topic:
Active Server Pages (ASP);;JavaScript
Dear Exerts,
I try to extract the total execution time of the for loop in the following asp code
and since vbscript is not doing well with miilli-second extraction, so I use javascript code
for extracting time in ms from start and ending of for loop.
Now the code is working, it show the Start and End time. But how to
do substraction on start-time - end time ?
I tried put the end-time javascript right after <% %> similar code to the start time javascript code. But it showed the wrong result that is why I put into head tag for end time javascript code.
Any better approach for doing that ?
Please advise
Rwniceing
I try to extract the total execution time of the for loop in the following asp code
and since vbscript is not doing well with miilli-second extraction, so I use javascript code
for extracting time in ms from start and ending of for loop.
Now the code is working, it show the Start and End time. But how to
do substraction on start-time - end time ?
I tried put the end-time javascript right after <% %> similar code to the start time javascript code. But it showed the wrong result that is why I put into head tag for end time javascript code.
Any better approach for doing that ?
Please advise
Rwniceing
<!DOCTYPE html><html><script language=javascript runat=server>var myvar = Date.UTC(a.getFullYear(),a.getMonth(),a.getDay(),a.getHours(),a.getMinutes(),a.getSeconds(),a.getMilliseconds()); response.write("Start time in ms: " + myvar ); </script><%Dim i,a,b,cfor i = 1 to 2e6a=1234+5678+ib=1234*5678+ic=1234/2+inextresponse.write("<br/>(i,a,b,c)=" & i & "=" & a & "=" & b & "=" &c & "<br/>")%><body></body><head runat="server"> <title>Demo Page for Test</title> <script language="javascript" type="text/javascript" > var a = new Date();var myvar = Date.UTC(a.getFullYear(),a.getMonth(),a.getDay(),a.getHours(),a.getMinutes(),a.getSeconds(),a.getMilliseconds()); document.write("End time in ms: ",myvar); </script></head></html> 1:2:3:4:5:6:7:8:9:10:11:12:13:14:15:16:17:18:19:20:21:22:23:24:25:26:
Author: rwniceing replied at 2024-08-29 05:34:59
Done and thanks for your reply
Author: rwniceing replied at 2024-08-29 05:33:16
<%Option ExplicitResponse.Buffer = False ' not needed but lets you see the output as it is produced instead of all at once%> 1:2:3:4:5:6:7:
That is why on my topic post code, it will response.write the output after the for loop completion
and the start and end time is also correct but just echo out at the same time that is strange I feel.
Probably it is caused by the setting on response.buffer.
Accepted Solution
Expert: Robert Schutt replied at 2024-08-29 05:26:55
500 points EXCELLENT
I've struggled with this in the past (regarding time zone offset which also seemed strangely unavailable in ASP/VB). One of the problems when mixing languages and embedded code blocks with server script tags is keeping tabs on which code is executed when. One way to avoid this problem is to wrap the needed (server side) javascript in a function which can be called from (server side) vb script. Your specific situation could be solved as follows:
<%Option ExplicitResponse.Buffer = False ' not needed but lets you see the output as it is produced instead of all at once%><!DOCTYPE html><html><body> <script language="jscript" runat="server"> function getTime() { var a = new Date(); return Date.UTC(a.getFullYear(),a.getMonth(),a.getDay(),a.getHours(),a.getMinutes(),a.getSeconds(),a.getMilliseconds()); } </script><%Dim startTime, endTimestartTime = getTime()Response.Write "Start time in ms: " & startTimeDim i,a,b,cfor i = 1 to 2e6a=1234+5678+ib=1234*5678+ic=1234/2+inextresponse.write("<br/>(i,a,b,c)=" & i & "=" & a & "=" & b & "=" &c & "<br/>")endTime = getTime()Response.Write "End time in ms: " & endTimeResponse.Write "<br>Elapsed time in ms: " & (endTime - startTime)%></body></html> 1:2:3:4:5:6:7:8:9:10:11:12:13:14:15:16:17:18:19:20:21:22:23:24:25:26:27:28:29:30:31:32:33:34:35:36:37:38:
Note that I added some bells and whistles just for fun...