With the following code, the function only msgbox's "variable declaration" and "before for/each". i put them in there for debugging when i saw that my function wasn't getting all the way through.

Any suggestions?

Option Explicit

Function ArrToCSV(ByVal array)
	msgbox "variable declaration"
	Dim strTemp
	Dim strQuote
	Dim x
	strQuote = Chr(34)
	msgbox "before for/each"
	For each x in array
		msgbox x
		strTemp = strTemp & strQuote & x & strQuote & vbcrlf
	Next
	msgbox "after for/each"
	Set ArrToCSV = strTemp
End Function

I've also tried un-abstracting (lol..) the function back into the code block, and even tried a standard for/next loop using Ubound(array), but still no luck. it gaffs right as it hits the 'for' :(

However,

msgbox array(0) & vbcrlf & array(1) & vbcrlf & array(2)

shows the first the elements of the array, as expected.

I'm stuck.

------
FYI: My array isn't actually named "array"; i just did it like that because it was the first thing that came to mind when i was posting.
------

Not quite sure what you are trying to accomplish but...

MsgBox Join(MyArray, vbNewLine)

Good Luck

Not quite sure what you are trying to accomplish but...

MsgBox Join(MyArray, vbNewLine)

Good Luck

The second post was just stating taht i know for a fact that the data is in that array, because i can pick apart elements of it and look at them.

I'm trying to put an array into a readable csv format, but because some of the elements have double quotes in them, i cant just simply do a 'join'; i have to wrap the entire element in quotes, hense the Chr(34)'s

i still dont see anything wrong with the syntax of my loop or function.

Well then go with the LBound/UBound to make sure you don't run out of bounds...

For ForLoopCounter = LBound(MyArray) To UBound(MyArray)
  '...

Good Luck

Well then go with the LBound/UBound to make sure you don't run out of bounds...

For ForLoopCounter = LBound(MyArray) To UBound(MyArray)
  '...

Good Luck

I think you found my problem. One of the arrays i was passing to this function had an LBound of 1, not 0, so it was crapping out.

thanks for the help!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.