Print Page | Close Window

Random Image Generator

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=13308
Printed Date: 30 March 2026 at 11:05pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Random Image Generator
Posted By: skwfalcon16
Subject: Random Image Generator
Date Posted: 11 January 2005 at 6:29am
Alright, I've run into a problem. I'm setting up an image gallery and want to show a random image from each folder in the gallery on the main page. I can get the picture to show up, but my problem is it's always the same picture. I'm not real sure what I'm missing.
 
Here's the code:
 
Set fso = Server.CreateObjec("Scripting.FileSystemObject")
Set rootFolder = fso.GetFolder(Server.MapPath(strFileUploadPath))
Set subFolder = rootFolder.SubFolders
For each x in subFolder
 num=num+1   
 set fso2=Server.CreateObject("Scripting.FileSystemObject")
 set rootFolder2=fso2.GetFolder(Server.MapPath(strFileUploadPath & "\" & x.name))
 LastMod = rootFolder2.DateLastModified
 Response.Write (vbCrLf & "    <td valign=""top"" align=""center"" bgcolor=""" & strTableColour & """ background=""" & strTableBgImage & """ class=""text"">")
 Response.Write ("<br />")
 Response.Write (vbCrLf & "    <a href=""forum_photos.asp?" & x.name & """ class=""boldLink"">" &  x.Name & "</a><br />")
 
  imgdir = strFileUploadPath & "\" & x.name
  Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
  Set objFolderObject = objFSO.GetFolder(Server.MapPath(imgdir))
  Set objFSO = Nothing
  Set objFileCollection = objFolderObject.Files
  Set objFolderObject = Nothing
  intFileNumberToUse = Int(rnd * objFileCollection.Count) + 1
  If objFileCollection.Count = 0 Then
   Response.Write ("<br />No Pictures In Gallery<br /><br />")
  Else  
  
  intFileLooper = 1
  For Each objFile in objFileCollection
   If intFileLooper = intFileNumberToUse Then
    Set objImageFileToUse = objFile
    Exit For
   End If
   intFileLooper = intFileLooper + 1
  Next
  Set objFileCollection = Nothing
  strImageSrcText = imgdir & "\" & objImageFileToUse.Name
  Set objImageFileToUse = Nothing
  Response.Write ("<br />")
 Response.Write (vbCrLf & "    <a href=""forum_photos.asp?" & x.name & """><img src=""/thumbnailimage.aspx?filename=" & strImageSrcText & "&width=" & ImgWidth &"&height=" & ImgHeight & """ border=""0"" align=""middle""></a><br / >")
 Response.Write ("<br />")
 
 End If
 
 Response.Write LastMod 
 Response.Write (vbCrLf & "    </td>")
  
 numGallery = numGallery + 1
    
 If numGallery = 3 Then
  Response.Write (vbCrLf & "  </tr>")
  Response.Write (vbCrLf & "  <tr>")
  numGallery = 0
 End if
Next    
 If numGallery <> 0 Then
  Do While numGallery <= 2
   Response.Write (vbCrLf & "    <td valign=""top"" bgcolor=""" & strTableColour & """ background=""" & strTableBgImage & """ class=""text"">&nbsp;</td>")
   numGallery = numGallery + 1
  Loop
  Response.Write (vbCrLf & "  </tr>")
 End If
 
Any help would be greatly appreciated!


-------------
http://www.spreadfirefox.com/?q=affiliates&id=179077&t=82">



Replies:
Posted By: Phat
Date Posted: 12 January 2005 at 6:25am
Try putting Randomize before
 intFileNumberToUse = Int(rnd * objFileCollection.Count) + 1


Posted By: skwfalcon16
Date Posted: 12 January 2005 at 3:12pm
Awesome!
 
That worked...thanks!


-------------
http://www.spreadfirefox.com/?q=affiliates&id=179077&t=82">



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net