Display a Random Image   
 
This function is very useful when you need to randomly display a series of graphics. Simple save them into a folder and apply this function. Please note this function accepts virtual directory as argument, you can modify it to accept absolute harddrive directory.

<%
Function RandomImage(strPath)
    Randomize()

    If Right(strPath, 1) <> Chr(47) Then strPath = strPath & Chr(47)
    strPhysical = Server.MapPath(strPath)
    Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
    Set objFolder = objFSO.GetFolder(strPhysical)
    Set objFiles = objFolder.Files

    For Each objFile in objFiles
      strFile = LCase(objFile.Name)
      strFiles = strFiles & strFile & vbTab
    Next

    strImages = Split(strFiles, vbTab)
    
    If UBound(strImages) > 1 Then
      RandomImage = strPath & strImages(Int(Rnd(1)*UBound(strImages)))
    End If
End Function
%>

Usage:
<IMG SRC="<%=RandomImage("/images")%>" border=1>

The Result:


My3C's
perrychicker
It's easy... it's a PSACAKE!
Back | Tell A Friend | Search this Site
© 1998 - 2010 psacake.com
Version 3.23

Send me One Million FREE Guaranteed Visitors