[thelist] ASP and CSV function nightmare

Christopher Joseph christopher at ideadesigners.com
Fri Sep 19 11:54:30 CDT 2003


Hi List,

I am having an ASP friday afternoon nightmare today...

First off - ASP/VBscript is NOT my bag baby. Regardless I have an ASP 
function that I have coded to retrieve a CSV file from the file 
structure and return the contents as an array.

The function is as follows.

	
	Function ReturnArray (strMenuIn, strSubMenuIn, strMenuLevel)
		Dim arrMenu, strPath, objFso
		Dim arrDummy(0) 'BIG KLUDGE
		
		'build path to menu order csv.
		If strMenuLevel = "section" Then
			strPath = Server.MapPath("/") & "\" & SECTIONPATH
		Else
			If strMenuLevel = "menu" Then
				strPath = Server.MapPath("/") & "\" & SECTIONPATH  & "\" & strMenuIn
			Else
					If strMenuLevel = "submenu" Then
						strPath = Server.MapPath("/") & "\" & SECTIONPATH  & "\" & 
strMenuIn & "\" & strSubMenuIn
					End If
			End If
		End IF
		strPath = strPath & "\" & "order.csv"
		Set objFso = CreateObject("Scripting.fileSystemObject")
		If objFso.FileExists(strPath) then
			Set objTxtStream = objFso.OpenTextfile( strPath )
			arrMenu=split(objTxtStream.ReadAll,",")
			'return array
			ReturnArray = arrMenu
		Else
			'return dummy array
			ReturnArray = arrDummy
		End If

		'Clean up
		Set objFSO = Nothing
	
	End Function	


Since this function is now firmly embedded in the rest of the code I 
always need to return an array. BUT if the CSV is blank or only contains 
one element and therefore doesn't contain any commas the split() 
function seems to do nothing and the function tries to return a normal 
variable.

e.g. CSV with only one item

[BOF]ItemOne[CRLF][EOF]

...as opposed to a CSV with more than one.

[BOF]ItemOne,ItemTwo,ItemThree[CRLF][EOF]

How should I fix it so that:

It always returns an array even if it has only one element.

Thanks for your hepl in advance.
-- 
Christopher Joseph

-------------------
[Internet]
http://www.ideadesigners.com  [iseries & web technologies]
mailto: christopher at ideadesigners.com




More information about the thelist mailing list