Random Includes

Results 1 to 6 of 6

Thread: Random Includes

  1. #1
    GJM Guest

    Default Random Includes

    I posted yesterday and hope someone can answer my question. I have a place on a page where I want to present little factoids. I have 25 of them (fact01.asp, fact02.asp,...). I want to arrange a script so when the user refreshed the page, a new factoid appears. <BR><BR>Rather than putting all the factoid in the header with JavaScript and using a random text script (page already has too much weight), I want to put them in as includes &#060;!--include="factoids/fact01.asp--&#062;. Is this even possible? <BR><BR>Thanks so much.

  2. #2
    Sid Guest

    Default RE: Random Includes

    Not as an include , but if you are only using IE then ..<BR>Insert an &#060;iframe&#062;&#060;/iframe&#062; and set its source to<BR><BR>&#060;iframe src="myfolder/myfile&#060;%=myVar%&#062;.asp"&#062;<BR>using my var as a random number , you could use the Application("NumVisits") to change the myVar . Might lead you in the right direction.

  3. #3
    MG Guest

    Default Bill W. answered your question yesterday!!!!!

    Here is Bill&#039s answer since you did not read your own thread.<BR><BR>You can&#039t do conditional includes in ASP. The includes happen *before* the ASP processing.<BR><BR>Further, an include file has to follow coding rules.<BR><BR>You could do this:<BR><BR>&#060;%<BR>text = "&#060;!-- #include ... --&#062;"<BR>%&#062;<BR><BR>But then the file could not include any RETURN characters or you&#039d be messing up the VBScript syntax.<BR><BR>ALSO, if you did this:<BR><BR>&#060;%<BR>SELECT CASE CInt(Second(Now)) MOD 4 <BR>CASE 0<BR> text = "&#060;!-- #include ... --&#062;"<BR>CASE 1<BR> text = "&#060;!-- #include ... --&#062;"<BR>CASE 2<BR> text = "&#060;!-- #include ... --&#062;"<BR>CASE 3<BR> text = "&#060;!-- #include ... --&#062;"<BR>END SELECT<BR>%&#062;<BR><BR>It might work (again, if you were *REAL* careful about the include file contents!), but ALL FOUR include files would *ALWAYS BE INCLUDED*. <BR><BR>So what have you gained over simply putting the text right into the ASP file?<BR><BR>How about something like this, instead:<BR><BR>&#060;%<BR>CONST NumberOfTextFiles = 4<BR>choice = 1 + Int( Rnd * NumberOfTextFiles ) <BR>SET FSO = Server.CreateObject("Scripting.FileSystemObject")< BR>SET cFile = FSO.OpenTextFile( Server.MapPath( "MessageFile" & choice & ".txt" )<BR>text = cFile.ReadAll<BR>cFile.Close<BR>%&#062;<BR><BR>See it? If your files are named "MessageFile1.txt", "MessageFile2.txt", ... then just set that CONST to match how many there are and you are done.<BR><BR><BR>

  4. #4
    GJM Guest

    Default RE: Bill W. answered your question yesterday!!!!!

    I chose to ask again to see if I could get a different response. Obviously, I can&#039t.

  5. #5
    MG Guest

    Default RE: Bill W. answered your question yesterday!!!!!

    This is a faily common question and Bill&#039s answer is the best I have seen and is very easy to implement!!!

  6. #6
    Join Date
    Dec 1969

    Default Same question gets same answer...

    First, thanks MG, for the kind words.<BR><BR>To GJM:<BR><BR>If you want different answers, ask a different question.<BR><BR>You *can not* do dynamic includes in ASP. Period, period, period. Your response ("Obviously...") makes it sound like you are killing the messenger for delivering the truth to you. <BR><BR>But *ANY* beginning ASP book will tell you the same thing if you choose not to believe me. Are you going to kill those messengers, as well?<BR><BR>There *are* other ways to accomplish this (including Server.Execute), but the answer I gave you is likely the most efficient one you will find.<BR><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