- ASP - Random Functions
·Script Writers
·Database Display
·Response Objects
·Server Variables
·Random Events
·What's New?
Mail List


Reading Random Text
Reading text from an outside source is easily accomplished with an include statement similar to this <!--#include file=""-->.  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

<title> Random Text)</title>
<body bgcolor="#FFFFFF">

Beginning of area for dynamic text include
' Select a random number from one to five

' 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

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

End of area for dynamic text include




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 is hosted by
    Donate Food Online with a Mouse Click at
    Donate Land Online with a Mouse Click at
    © 1999 - 2018
    All Rights Reserved

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