Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie - Can this be done with ASP ? 1

Status
Not open for further replies.

Thorex

Technical User
Nov 1, 2001
4
HR
Hi there to you all!

Can ASP do this ?

Lets say that the page has two frames, and on 50 loads of that page, the lower frame displays one location, and on next 50 loads some other location, can that be done, and how?

Thanks, and sorry for the stupidity of the question :))
 
Sure,

In your global.asa file you can do this.
Code:
Sub Application_OnStart
  Application("pagehits") = 0
End Sub

Then you place the following code in your frameset page.
Code:
<%
dim pageref
pageref = &quot;somepage.asp&quot;
IF Application(&quot;pagehits&quot;) > 50 THEN
  Application.Lock
  Application(&quot;pagehits&quot;) = 0
  Application.Unlock
  pageref = &quot;someotherpage.asp&quot;
ELSE
  Application.Lock
  Application(&quot;pagehits&quot;) = Application(&quot;pagehits&quot;) + 1
  Application.Unlock
END IF
%>

<frame name=&quot;lowerframe&quot; src=&quot;<%=pageref%>&quot; ....>

Remember, the counter goes to zero each time the application or server is re-started.

Does that make sense ??

ToddWW
 

Thanx ToddWW great help, but wouldnt this part:


pageref = &quot;somepage.asp&quot;
IF Application(&quot;pagehits&quot;) > 50 THEN
Application.Lock
Application(&quot;pagehits&quot;) = 0
Application.Unlock
pageref = &quot;someotherpage.asp&quot;

load the somepage 50 times, then load someotherpage once and then again somepage for next 50 times, I would like to show the someotherpage for 50 times

Any Idea ?

Thank you
 
Yeah. I was sort of generalizing there since I didn't know what convention you planned on using to store and retrieve the different page addresses. How many different pages did you want to have the system loop through ?? Have you thought about where you want to store these. We could just store them in an include text file and build an array in ASP each time the page loads. ASP will dump the array from memory right after the ASP page processes so unless we're talking about 1000's of different pages, this might be the way to go.

Your thoughts ??

ToddWW
 
Hi there again ToddWW !!

My thoughts:

You're pure Gold at least from my point of view

Idea is Great, so lets say we have 10 different pages, and each would load 50 times

How to do it ??

Once again Thank You






 
Well, here's my thinking. You can add another application variable like this.
Code:
<%
Sub Application_OnStart
  Application(&quot;pagehits&quot;) = 0
  Application(&quot;pageindex&quot;) = 0
End Sub
%>

Then modify the code in the frameset like this.
Code:
<%
dim pageCount
pageCount = 10

dim pageList(pageCount)
pageList(0) = &quot;page1.asp&quot;
pageList(1) = &quot;page2.asp&quot;
pageList(2) = &quot;page3.asp&quot;
pageList(3) = &quot;page4.asp&quot;
pageList(4) = &quot;page5.asp&quot;
pageList(5) = &quot;page6.asp&quot;
pageList(6) = &quot;page7.asp&quot;
pageList(7) = &quot;page8.asp&quot;
pageList(8) = &quot;page9.asp&quot;
pageList(9) = &quot;page10.asp&quot;

IF Application(&quot;pagehits&quot;) > 50 THEN
  Application.Lock
  Application(&quot;pagehits&quot;) = 0
  IF Application(&quot;pageindex&quot;) >= pageCount-1 THEN
    Application(&quot;pageindex&quot;) = 0
  ELSE
    Application(&quot;pageindex&quot;) = Application(&quot;pageindex&quot;) + 1
  END IF
  Application.Unlock
ELSE
  Application.Lock
  Application(&quot;pagehits&quot;) = Application(&quot;pagehits&quot;) + 1
  Application.Unlock
END IF

dim i
i = Application(&quot;pageindex&quot;)
pageref = pageList(i)
%>

<frame name=&quot;lowerframe&quot; src=&quot;<%=pageref%>&quot; ....>

Do you see what we've done there. Basically we added another application counter. It represents what page we're currently loading into the frameset. It's initialized at zero, so for the first 50 loads, that variable stays at zero. Now we create an array of pages called pageList() and in the last line of ASP code, we call the page assigned to the number in the application counter pageref = pageList(i). In this case, i represents 0 until that counter is incremented.

Here's what you need to know and understand. If you increase or decrease the number of pages, you need to make that change in two places. pageCount = x and then you'll need to modify the list. Now, the sort of tricky part is that VBScript arrays are zero based. So while you have 10 pages, the array starts at zero (and so does our counter). So for 10 pages, you actually have an array indexed 0-9. You can also see where I'm calling the pageCount variable in the conditional statement that increments the Application(&quot;pageindex&quot;) value. Notice how I set it to be pageCount-1. That's because of the zero based indexing. We want it to go back to zero if the pageindex is at 9 and someone has already loaded the frameset 50 times.

Is that making sense.

ToddWW
 
Hello ToddWW !!

This combination is not working for some reason, is it the code ? I used exact code, number of pages (10), and modifyed the pagelist like you said.
The two pages solution worked perfectly after modifying the code you gave me.

Please Help, and thanks for all the help before.

 
Tell me what's happening. Why isn't it working ??

ToddWW
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top