Login | |
|
 |
Passing arrays to Subs - 3/23/2006 3:24:38 AM
|
|
 |
|
| |
seanm
Posts: 15
Score: 0
Joined: 12/21/2005
From: Belfast, Ireland
Status: offline
|
Hi all, Im trying to write a script that reads through an XML file and populates a 2-dimensional array with certain attribute values. Im am using 2 subs to read through the XMl file, elements() - (recursive) - and attributes(). So far, by stepping through the code and using wscript.echo, I have determined that the script does read through the file and populate the array ok. Problem is when I use the for loop below to again test that the array is populated all I have returned is blank lines, obviously showing that the array is unpopulated. This has to do with how I am passing the array thorugh the 2 Subs, but I cant for the life of me find out where i'm going wrong!!!! for j = 0 to UBound(arrRainbow) WScript.Echo arrRainbow(j,0) next strHandback = "C:\Reports\report.xml" 'Create xml obj and load the sourceFile into it Set xmlDoc = CreateObject("Microsoft.XMLDOM") xmlDoc.async = false xmlDoc.load(strHandback) Dim arrRainbow(120, 2) elements xmlDoc '3rd test to see if array was populated - determined it was empty for j = 0 to UBound(arrRainbow) WScript.Echo arrRainbow(j,0) next Sub elements(XDoc) for each child in XDoc.childNodes if (child.nodeType =1) Then if (child.attributes.length > 0) Then attributes child end if end if if (child.hasChildNodes) Then elements child 'Recursive call end if next end Sub Sub attributes(node) for each att in node.attributes if( att.name = "fileName") Then 'FileName att is in for \<..>\<..>\<..>\fileName so had to trim() to get fileanme strLine = Trim(att.Value) If strLine<> "" Then arrrayFileLine = split(strline," ") str1 = arrrayFileLine(0) arrayLineContains = split(str1,"\") For J = 0 to UBound(arrayLineContains) strtext = arrayLineContains(J) Next On Error Resume Next Err.Clear arrRainbow(i, 0) = strtext End If 'WScript.echo arrRainbow(i, 0) '-- 1st test to see if array is being populated - shows that it was else if( att.name = "SessionId") Then arrRainbow(i, 1) = att.value WScript.echo arrRainbow(i, 1) '-- 2nd test to see if array is being populated - shows that it was i=i+1 end if end if next End Sub I have also tried passing the array as an addition parameter to the 2 Subs with the same result. Anyone see where i'm going wrong??? Thanks in advance. Sean
< Message edited by seanm -- 3/23/2006 3:36:30 AM >
|
|
| |
|
|
|
 |
RE: Passing arrays to Subs - 3/23/2006 9:08:00 PM
|
|
 |
|
| |
seanm
Posts: 15
Score: 0
Joined: 12/21/2005
From: Belfast, Ireland
Status: offline
|
Hi ebgreen, Firstly thanks for the reply. Just tried your suggestion there and the same result. When I tried to Echo the contents of the fileName row in the array all I got is the last FileName from the XML file in index = 0 of the array. I stepped through the script again the see if this had something to do with the way I am incrementing I but it hasn't. Any ideas?? Cheers, Sean
|
|
| |
|
|
|
 |
RE: Passing arrays to Subs - 3/24/2006 1:38:58 AM
|
|
 |
|
| |
seanm
Posts: 15
Score: 0
Joined: 12/21/2005
From: Belfast, Ireland
Status: offline
|
No no the for loop at the top was for explanation only. Just forgot to put in the [code] labels after it!!!
|
|
| |
|
|
|
 |
RE: Passing arrays to Subs - 3/24/2006 4:39:58 AM
|
|
 |
|
| |
seanm
Posts: 15
Score: 0
Joined: 12/21/2005
From: Belfast, Ireland
Status: offline
|
Excellent stuff Cheers mate. Thanks for your time and help. Slainte.
|
|
| |
|
|
|
|
|