Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing arguments to a function while returning an array 2

Status
Not open for further replies.

DeathSurfer

Programmer
Mar 7, 2007
7
US
Is it possible to pass an argument to a function that in turn returns an array? For some reason when I call the function getXmlElementNV from GetFBRData() below while passing an argument it will not pass the array back to me. The getXmlElementNV function gathers the node values from an xml file and is suppose to return them in an array. Can someone shed light?

------------------------------------------------------------

Sub GetFBRData()

'this loads and xml file
LoadXmlDoc ("C:\Excel Report Information.xml")

getXmlElementNV "worksheet_name"

End Sub
------------------------------------------------------------

Public Function getXmlElementNV(ElementName As String) As Variant

Dim xNodeList As IXMLDOMNodeList
'dim the xml element node value array
Dim xmlENVArray() As String

ReDim xmlENVArray(0)

Set xNodeList = xmlDoc.getElementsByTagName(ElementName)

Dim i As Long

For i = 0 To (xNodeList.Length - 1)
' make room for another worksheet in the array
ReDim Preserve xmlENVArray(i)
' add the worksheet to the array
xmlENVArray(i) = xNodeList.Item(i).childNodes.Item(0).nodeValue
Next i

' add the worksheets in the array to the output
getXmlElementNV = xmlENVArray

End Function

 
What happens if you replace this:
getXmlElementNV "worksheet_name"
with this ?
MsgBox UBound(getXmlElementNV("worksheet_name"))

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks PHV. This returned 2 in a message box and there was 3 items in the array so the array was getting passed. What confuses me is that when I step through the program and return back into the GetFBRData() subroutine, the watch that I set for getXmlElementNV "worksheet_name" function looks as if it loses scope and no array is in getXmlElementNV. Anyway, thanks for your help dude.
 
The magical stuff is in red:
getXmlElementNV[!]([/!]"worksheet_name"[!])[/!]

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Also, you're not assigning the returned value to anything (at least in your example).

_________________
Bob Rashkin
 
Thanks dudes. I'm a noob programmer so I've got a lot to learn. Preciate your help. Later.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top