ASP: Simple Content Rotator
Introduction
Author: Martin WarningYear: 2007
License: Free
This is a simple function that will show a different image each time the page is loaded. Instead of an image any content could be used to be rotated like a news item or a banner. This is a static rotator so it will only load a new image on page load, it's not able to rotate every X seconds, for that you would need a scripting language like JavaScript.
This is a very simple script that uses randomize to create a random number and a Select Case to display the content corresponding to the chosen random number. As it uses the randomize function the same content could be loaded twice or more in a row and some content might require a lot of page refreshes to be shown. This is the nature of the random function, but from a statistical view point all content should be show an equal ammount of times if it's shown often enough.
Code
Languages:- XHTML
- ASP
- VBScript
<% Function fncRandomContent() ' The function uses no passed variables ' Declare the variables required Dim intLowestNumber,intHighestNumber,intRandomNumber ' Generate a random number ' You will need to change intHighestNumber to match the highest number used in the case statement RANDOMIZE intLowestNumber = 1 intHighestNumber = 2 intRandomNumber = INT((intHighestNumber-intLowestNumber+1)*Rnd+intLowestNumber) ' The case statement with the different contents Select Case intRandomNumber Case 1 fncRandomContent = "<img src=""img1.gif"" alt="""" />" Case 2 fncRandomContent = "<img src=""img2.gif"" alt="""" />" Case Else fncRandomContent = "<img src=""img3.gif"" alt="""" />" End Select End Function %>
If so desired you can add more options to the case statement and this content could be any type like images, banners, links or text.