Forum Discussion

kinsleyd's avatar
kinsleyd
Contributor
15 years ago

Looping through an array

I'm populating an array with the FindAllChildren method, which is generating a list of all the links on a specific web page.  I then try to use the members of that array to open up those links.  For some reason, the ToURL method is locking the array after the first iteration of the loop and blows up directly there after:  blah2 is the array in question




If UBound(blah2) >= 0 Then


(blah2) >= 0

For i = o to ubound(blah2)


blah3 = Project.Variables.server & "gsa/webbas01.nsf/(vwwebpage)/" & blah2(i).nameProp


Set iexplore = Aliases.iexplore


iexplore.ToURL(blah3)'nav_to_page blah3


 


next


else msgbox("no values returned")


End If



I do not know how to overcome this.  Its interesting to note that if I use the NavigateTo method vs. ToURL the loop continues without error (there are actually message boxes in the code that verify this), but the navigateto method does nothing.  So I need a hybrid method of the ToURL / NavigateTo method - one that actually opens the page but does not lock the array subsequently.  That, or a way to get around the locking of the array, if that's what you call it.



Any advice is welcome.


6 Replies

  • Hi Dave,




    I think that there are two problems here. The first one is in this line:

    For i = o to ubound(blah2)




    You should uze '0' (zero) instead of O (a letter):

    For i = 0 to ubound(blah2)




    The second problem is that you try to get a link's URL using the 'nameProp' property that contains a stripped URL. You should use the 'href' property to get the actual link:

    Log.Message blah2(i).href


  • David,



    Nice spot on the O vs. zero.  Intriguing that the loop was still looping.  Go figure.



    I'm looking at the href property of one of the links (through the object browser) - here's what it is for one of the links on the page:

    javascript:showwindow('/gsa/webbas01.nsf/(vwwebpage)/webbase.htm?opendocument&login&Scope=PRJC____,App=Basics__________,ProjectID=1188')



    vs. the nameprop property of the same link:

    webbase.htm?opendocument&login&Scope=PRJC____,App=Basics__________,ProjectID=1188')



    So the href still isn't a full link (just as the nameprop isn't), and I'd have to play text games with it, stripping off the 'javascript:showwindow....  to get it to work vs. the way I'm doing it now (which works on the first iteration).  So I'm not sure I understand the advantage to using it vs nameprop.



    I recognize that its probably hard to tell what's going on with the other variables in the code I posted since you can't see where they're coming from.



    Correcting the zero had no effect sadly - still getting 'permission denied' on the second iteration of the loop if the ToURL method is n't commented out.  Works fine if I eliminate the ToURL method and just display the message box with the value of the array at that loop.  Got me stumped.

  • I tried using some script to open up a new window of IE to open up the generated link, and that seems to have gotten around the issue with the array.  It presents a few other hurdles, but at least I'm past that wacky array issue!



    Thanks for your help, David.
  • Its baaaack.

    Something tells me this is going to continue to haunt me until I have an understanding of why its happening.  Here's my revised code in its entirety:

    Sub List_Projects



    'loops through the main body and extracts the link property of all returned projects


    'Assumes a region has been selected



    dim iexplore, blah1, blah2, blah3, name_prop, name_prop_length


    Set iexplore = Aliases.iexplore


    set blah1 = iexplore.Page(Project.Variables.server & "gsa/webbas01.nsf/(vwwebpage)/webbase.htm?opendocument&Set=1,Scope=RPL_____,App=Basics__________,Select=P-Active-2,")


    blah2 = blah1.FindAllChildren("nameProp", "webbase*", 13)


    If UBound(blah2) >= 0 ThenFor i = 0 to 3'ubound(blah2)


               name_prop_length = len(blah2(i).nameProp)


               '  extract the project ID from the nameprop property:


             Select case name_prop_length


                       Case 80


                          Project.Variables.proj_id = mid(blah2(i).nameProp, 78, 1)


                       Case 81


                           Project.Variables.proj_id = mid(blah2(i).nameProp, 78, 2)


                        Case 82


                           Project.Variables.proj_id = mid(blah2(i).nameProp, 78, 3)


                         Case 83


                             Project.Variables.proj_id = mid(blah2(i).nameProp, 78, 4)


                         Case 84


                                Project.Variables.proj_id = mid(blah2(i).nameProp, 78, 5)


                      end Select


                      '                   run the sub to change the state to completed


               Change_Project_State


               next          else msgbox("no values returned")


               End If


    end Sub



    Now I'm calling another sub (Change_Project_state), which runs fine the first iteration, then the old "Permission Denied - blah(...).nameprop  appears.  Why!?????????


  • Hello Dave,




    Here is what happens:

    When you navigate to a page on the first iteration, all object references stored in the "blah2" array become invalid because all underlying objects disappear from the page. So, on the second iteration, the script will error out trying to address a non-existing object.




    To accomplish your task, I suggest that you store the nameProp property values of the found objects, not the object references. Something like this:




    AllChildren = blah1.FindAllChildren("nameProp", "webbase*", 13)




    For i = 0 to ubound(AllChildren)

      blah2(i) = AllChildren(i).nameProp

    Next




    If UBound(blah2) >= 0 Then

      For i = 0 to ubound(blah2)

               name_prop_length = len(blah2(i))

    ...




    Does this work for you?