CodeAve.com CodeAve.com - ASP - Random Functions
ASP
·Read/Write
·Script Writers
·Database Display
·Response Objects
·Server Variables
·Random Events
·Articles
·Miscellaneous
·Contents
·What's New?
JavaScript
CSS
HTML
Maps
Links
Mail List
Search
Sitemap


 


Reading Random Text
Reading text from an outside source is easily accomplished with an include statement similar to this <!--#include file="file.inc"-->.  If you wanted to dynamically include text you would like to be able to do something similar to this <!--#include file="file" & random_number &".inc"-->.  The only problem is since include statements are resolved before just about anything else you'll get an error trying to dynamically write the name of the file you're attempting to include.  You can write a select case statement or an if then statement to resolve this, but understanding that the server will be resolving many includes to display the contents of one is kind of wasteful.  Providing that you're only passing code for the client to interpret (HTML, JavaScript, etc) you can dynamically include text into your asp document.  The following example will randomly select a number between one and five, read the contents of a .htm file and write it out to the browser.  The file that is being included does not have to be .htm just text based. The .htm extension was chosen on the off chance anyone may hit the page directly, so it would display rather than download. Refresh the output page for a more complete demonstration.
View the Output
Text View
Print View
Mail this Link
Download the Code

<html>
<title>CodeAve.com(Read Random Text)</title>
<body bgcolor="#FFFFFF">

Beginning of area for dynamic text include
<hr>
<% 
' Select a random number from one to five
randomize
random_number=int(rnd*5)+1

' Assign the variable page_to_read with
' the file being requested 
' (incorporating the random number into the file name
page_to_read="text"& random_number &".htm"

' Open the document to be read
set fso = createobject("scripting.filesystemobject")
set act = fso.opentextfile(server.mappath(page_to_read))

'read all the text on the document
read_text = act.readall 

' Close the document
act.close

' Write out the contents of the document
' to the browser
response.write read_text
%>


<p>
<hr>
End of area for dynamic text include
</html>

 

 

 



ASP: What's New? | Articles | Script Writers | Database Display | Read/Write
Server Variables | Response Objects | Random Events | Miscellaneous
HTML: Forms | Hyperlinks | Headers | Tables | Hyperlinks | Headers | Text Display
JavaScript: Document Info | Forms | Images | Navigation | Script Writers
CSS: Basics | Page Display | Text Display | Script Writers | Miscellaneous
  • 2014 michael kors
  • air max women 2013
  • 2014 michael kors
  • air max 2014
  • oakley glasses
  • oakley glasses

  • Maps: Map Script Writers | Bing Maps | Google Maps
  • bottes fr
  • ugg boot
  • Privacy Statement

    CodeAve.com is hosted by MyHosting.com
    Donate Food Online with a Mouse Click at TheHungerSite.com
    Donate Land Online with a Mouse Click at TheRainForestSite.com
    © 1999 - 2017 CodeAve.com
    All Rights Reserved

  • Kids jordan 6 rings
  • Jordan retro 10
  • Jordan retro 3