Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Passing arrays to Subs

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,32567
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Passing arrays to Subs
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 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 >
 
 
Post #: 1
 
 RE: Passing arrays to Subs - 3/23/2006 7:59:40 AM   
  ebgreen


Posts: 5246
Score: 31
Joined: 7/12/2005
Status: offline
What happens if you explicitly pass the array to the subs like this:


      

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to seanm)
 
 
Post #: 2
 
 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 

(in reply to ebgreen)
 
 
Post #: 3
 
 RE: Passing arrays to Subs - 3/24/2006 1:06:14 AM   
  ebgreen


Posts: 5246
Score: 31
Joined: 7/12/2005
Status: offline
In that case could you post a sample of the xml file so I can test with the same data you are using?

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to seanm)
 
 
Post #: 4
 
 RE: Passing arrays to Subs - 3/24/2006 1:27:35 AM   
  seanm


Posts: 15
Score: 0
Joined: 12/21/2005
From: Belfast, Ireland
Status: offline
 
Yeah no problem - here it is:


      

As you can see its a simple enough xml file - not that it matters as the Subs I have would work for most XML files.
Stepping thorugh the code shows that the array is being populated OK - just doesnt stay populated for some reason....

Thanks again,
Sean

(in reply to ebgreen)
 
 
Post #: 5
 
 RE: Passing arrays to Subs - 3/24/2006 1:34:09 AM   
  ebgreen


Posts: 5246
Score: 31
Joined: 7/12/2005
Status: offline
Is what you have posted in the OP your entire code? If so, then you should be getting an error on the very first line.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to seanm)
 
 
Post #: 6
 
 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!!!


(in reply to ebgreen)
 
 
Post #: 7
 
 RE: Passing arrays to Subs - 3/24/2006 3:19:08 AM   
  ebgreen


Posts: 5246
Score: 31
Joined: 7/12/2005
Status: offline
Ok, so here are some things that I found out:

1) You cannot have < or > in an attribute.
2) You were checking to see if the attribute name was "Filename", but none of the attributes are named that. I assume you meant to check for "RBFileName".
3) Else If is not a valid construct. It should be ElseIf.
4) The variable you use to index the array (i) is not global so it gets reset to 0 every time the attribute sub is called.

Here is corrected code:

      

and the corrected xml:

      

< Message edited by ebgreen -- 3/24/2006 4:17:32 AM >


_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to seanm)
 
 
Post #: 8
 
 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.

(in reply to ebgreen)
 
 
Post #: 9
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Passing arrays to Subs Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts