CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Jan 2009
    Posts
    32

    Strange VBA code to access webpage

    Hi,

    My question is about the following code I came across. The code works fine.
    Note that there is no dot between forms(0) and (i) in the if statement. As far as I know, in VBA there is always a dot between an object and its child object. Why no dot here?




    Code:
     
      For i = 0 To ie.Document.forms(0).Length - 1
            
            If ie.Document.forms(0)(i).Type = "submit" Then
                ie.Document.forms(0)(i).Click
                Exit For
            End If
    
        Next i
    Thanks,

    MG.

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: Strange VBA code to access webpage

    I'd say that that denotes an array with multiple dimensions, i.e a 2 dimesnional array :

    http://www.cpearson.com/excel/VBAArrays.htm

  3. #3
    Join Date
    Jan 2009
    Posts
    32

    Re: Strange VBA code to access webpage

    HanneSThEGreaT,

    Thanks for that. However, in the code there was no array defined. The code is trying to manipulate objects of a webpage which are not in array format.

    MG.

  4. #4
    Join Date
    May 2002
    Posts
    10,943

    Re: Strange VBA code to access webpage

    Hannes is correct...it is an array...but not how you would think. It is a multidimensional array of HTML elements.

    ie.Document.forms returns an array of all form elements within the page. So, ie.Document.forms(0) references the first form. ie.Document.forms(0)(i) is looping through each of the child elements of the form. If that element is a submit button (type="submit"), then it performs a mouse click on that element.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  5. #5
    Join Date
    Jan 2009
    Posts
    32

    Re: Strange VBA code to access webpage

    PeejAvery,

    Thanks. Is the form only object that shows its elements in array form?

    MG.

  6. #6
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: Strange VBA code to access webpage

    Not necessarily, but in this case yes.

    Remember, the Document Object Model is bascially what you should look up.

    The document is the webpage itself, and it hosts an array of controls, for example, if you have a web page with 3 tables on it, that will be an array of tables and so on

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured