[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 399
  • Last Modified:

VBScript Runtime error occuring on Linux server with Sun Java System Active Server Pages installed.

I created a new web site in asp, using VB Script to produce some dynamic elements. It was created ona computer running ISS. Once it was migrated to a server running Linux, with Sun Java System Active Server Pages loaded on it to run the asp pages, it started throwing an error (see below.)

*********
Error Type:
Sun ONE ASP VBScript runtime (0x800A0009) Subscript out of range /new-web/web-site/index.asp, line 150
***********

I have attached the code of the funtion that is causing the error, which occurs at the line:
file_name = parts(0)
I can see no reason why this error is happening, and need help.

Thanks

Lee
<%
			'More complex function that requires use of server functions and means any image can be dropped into
			'the RandomImage folder. It must be a gif or jpg, although a parameter can be added into the function
			'to deal with other image types.
 
			Function RandomImage(ImagesFolderPath, ImageFileTypes, ImageDescription)
 
			'Declare variables
			Dim CompleteImagesFolderPath
			Dim FileSystemObject
			Dim ImageFolder
			Dim Files
			Dim i
			Dim ImageFiles
			Dim File
			Dim FileName
			Dim FileExtension
			Dim RandomNumber
			
			'Find the complete path to image folder by using Server.MapPath
			CompleteImagesFolderPath = Server.MapPath(ImagesFolderPath)
			
			'Create an instance of the FileSystemObject which allows ASP to
			'access the file system 
			Set FileSystemObject = Server.CreateObject("Scripting.FileSystemObject")
			
			'Check that the folder containing the images exists
			If Not FileSystemObject.FolderExists(CompleteImagesFolderPath) Then
			RandomImage = "Error 0: Cannot find requested folder"
			Set FileSystemObject = nothing
			Exit Function
			End If
			
			'Get the folder containing the images
			Set ImageFolder = FileSystemObject.GetFolder(CompleteImagesFolderPath)
			
			'Get a list of all the files within the images folder
			Set Files = ImageFolder.Files
			
			'Use a dictionary object to temporarily store the image file names
			i = 1
			Set ImageFiles = Server.CreateObject("Scripting.Dictionary")
			
			'Loop through the list of files within the images folder.
			'If the file has a file extension that is in the list of
			'file types specified in the ImageFileTypes function parameter,
			'then add the file name to the ImageFiles dictionary object
			For Each File in Files
			
			FileName = File.Name
			FileExtension = Right(FileName, Len(FileName) - (InStrRev(FileName, ".")))
			
			If InStr(1,ImageFileTypes,FileExtension,vbTextCompare) > 0 then
			ImageFiles.Add i, FileName
			i = i + 1
			End If
			
			Next
			
			'Destroy objects that are no longer required
			Set ImageFolder = nothing
			Set Files = nothing
			Set FileSystemObject = nothing
			
			'Initialise the random number generator
			Randomize
			
			' Check that image file(s) have been found
			If ImageFiles.Count = 0 Then
			RandomImage = "Error 1: Requested folder does not contain any image files"
			Exit Function
			End If
			
			'Generate a random number between 1 and the number of image files
			RandomNumber = Int((ImageFiles.Count) * Rnd + 1)
			
			'Return a hyperlink to a random image file
			RandomImage = "<img src=" & Chr(34) & ImagesFolderPath & ImageFiles.Item(RandomNumber) & Chr(34) & " alt=" & Chr(34) & ImageDescription & Chr(34) & "width='150px' height='150px'>"
			
			'This function will strip out the filename and use it as a Caption for the picture
			Dim Caption
			Caption = ImageFiles.Item(RandomNumber)
			parts = split(Caption, ".")
			file_name = parts(0)
			ext = parts(1)
			Caption = "<div class='caption'>" & file_name & "</div>"
			Response.Write(Caption)
 
			Set ImageFiles = nothing
			
			End Function
			
			'Call the function and write to the screen, passing in the arguments for the function.
			Response.Write RandomImage("RandomImage/", "gif jpg", "Plasmocom")
			
			
 
			'The function has three arguments. The first (ImagesFolderPath) is 
			'the name of the folder containing the images in this case Random Image, 
			'and it should be a sub-folder of the folder that contains the ASP document. 
			'The second argument should be a string containing a list of file types to use 
			'as images (e.g. jpeg, jpg, gif). Finally, the last argument is a 
			'short sentence to describe your image (which is used as the images ALT tag).
			%>

Open in new window

0
wattie187
Asked:
wattie187
  • 4
  • 3
1 Solution
 
dosthCommented:
it means after split for . no data is come there as a result

after split check for ubound
parts = split(Caption, ".")
if ubound(parts)>=1 then

                        file_name = parts(0)
                        ext = parts(1)
end if
0
 
jmundsackCommented:
dosth is correct -- but maybe the problem is deeper than checking for whether the string contains a dot.  Is there something about Linux / Apache that would cause file names not to return file extensions?  Or something about the implementation of FileSystemObject on the Linus OS?  You may want to run some simple tests using FileSystemObject and see if there is something different in the implementation of how file names are being presented in the new environment.
0
 
wattie187Author Commented:
I have sent the new file to the customer and am awaiting a response. But you may be right in your thinking of the FileSystemObject but I won't be able to tell until they email me back.

Thanks
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
dosthCommented:
sounds good
0
 
wattie187Author Commented:
Can't get a meeting with the customer till Wednesday, but I think dosth could be getting the points as he seems to have solved the original error. Another question might be posted to see if the root problem gets sorted, if I can't work round it myself.

Cheers
0
 
dosthCommented:
Thanks Watt
0
 
wattie187Author Commented:
Thanks for the help, this solved my problem although it did uncover a bigger one :) Got it all sorted in the end. Thanks again.
0
 
dosthCommented:
Thanks again for the points
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now