Value passed sooner

1. Senior Member
Join Date
Dec 1969
Posts
451

## Value passed sooner

I have a loop in one of my ASP pages (middle of the page), this loop generates a value. Is there a way to show this value in at the top of the page when it is first loaded. I have tried adding the value to a function at the top of my page and writing response.buffer = true, but this does not seem to work...any suggestions...<BR><BR>Code as follows:<BR><BR>&#060;%@ Language=VBScript %&#062;<BR>&#060;% Response.Buffer = True %&#062;<BR>&#060;%<BR>sub addtoProblem1(buf)<BR> if problems1 &#060;&#062; "" then problems1 = problems1 & "<BR>"<BR> Problems1 = Problems1 & buf<BR>end sub<BR>%&#062;<BR>&#060;html&#062;<BR>&#060;head&# 062;<BR>&#060;/head&#062;<BR>&#060;body&#062;<BR>Write the output here &#060;%=problems1%&#062;<BR>Here is where we do the loop:<BR>&#060;%<BR>j = 0<BR>For i = 1 to 50<BR>j = j + 1<BR>NEXT<BR>addtoproblem1(j)<BR>%&#062;<BR>&#060 ;/body&#062;<BR>&#060;/html&#062;

2. Senior Member
Join Date
Dec 1969
Posts
96,118

## Why not just move the loop????

And what&#039;s the point of the SUB in there???<BR><BR>And of course if you know elementary algebra, you don&#039;t need a loop, at all.<BR><BR>The sum of integers from X to Y is always simply<BR> (X + Y) * (Y + 1 - X) / 2<BR>So the sum of integers from 1 to 50 is simply<BR> (1 + 50) * (50 + 1 - 1) / 2<BR>which is<BR> 51 * 50 * 2<BR>or<BR> 51 * 25<BR>which (doing this in my head) is...ummm...<BR> [ ... 50 * 25 is obviously 1250 (half of 50*50), so... ]<BR> 1275<BR><BR>Anyway, why does the loop have to be where it is??? Heck, it could even be *above* the SUB.<BR><BR>

3. Senior Member
Join Date
Dec 1969
Posts
451

## The loop

needs to be where it is at. This is not my exact code, I just wrote it real quick to give you an idea of the question I was asking, it is not really my code. Anyways, I can&#039;t move the loop, so I am wondering if this is possible?<BR><BR>Thanks

4. Senior Member
Join Date
Dec 1969
Posts
972

## RE: Value passed sooner

It does not make any sens to mee too why you want the loop where it is, but you could try something like this:<BR><BR>&#060;body&#062;<BR>Write the output here &#060;span id="mySpan"&#062;&#060;/span&#062;<BR>Here is where we do the loop:<BR>&#060;%<BR>j = 0<BR>For i = 1 to 50<BR>j = j + 1<BR>NEXT<BR>addtoproblem1(j)<BR>%&#062;<BR>&#060; script languague="JavaScript"&#062;<BR> document.getElementByid(&#039;mySpan&#039;).innerT ext = &#039;&#060;%=problems1%&#062;&#039;;<BR>&#060;/script&#062;<BR>&#060;/body&#062;<BR>

5. Senior Member
Join Date
Dec 1969
Posts
96,118

## Hokay..do it with JS...

&#060;HTML&#062;&#060;BODY&#062;<BR><BR>The total is &#060;SPAN ID="theTotal"&#062;OOPS?&#060;/SPAN&#062;<BR><BR>&#060;%<BR>&#039; any old looping code doing whatever<BR>total = 0<BR>for i = 1 to 10 <BR> total = total + i<BR>next<BR>%&#062;<BR>&#060;SCRIPT Language="javascript"&#062;<BR>// this can go any place in page *after* the VBS total is calculated<BR>document.getElementById("theTotal"). innerText = "&#060;%=total%&#062;"; <BR>&#060;/SCRIPT&#062;<BR><BR>&#060;HR&#062;<BR>Look, Ma! No cavities unfilled!<BR>&#060;/BODY&#062;&#060;/HTML&#062;<BR>

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•