Solved

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

Posted on 2008-06-26
8
386 Views
Last Modified: 2013-11-21
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
Comment
Question by:wattie187
  • 4
  • 3
8 Comments
 
LVL 15

Accepted Solution

by:
dosth earned 500 total points
ID: 21873377
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
 
LVL 13

Expert Comment

by:jmundsack
ID: 21873744
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
 

Author Comment

by:wattie187
ID: 21873970
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
 
LVL 15

Expert Comment

by:dosth
ID: 21874021
sounds good
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:wattie187
ID: 21897663
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
 
LVL 15

Expert Comment

by:dosth
ID: 21897689
Thanks Watt
0
 

Author Closing Comment

by:wattie187
ID: 31470918
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
 
LVL 15

Expert Comment

by:dosth
ID: 21923556
Thanks again for the points
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now