Click to See Complete Forum and Search --> : Strange VBA code to access webpage
musicgold
March 9th, 2010, 09:00 AM
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?
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.
HanneSThEGreaT
March 9th, 2010, 09:11 AM
I'd say that that denotes an array with multiple dimensions, i.e a 2 dimesnional array :
http://www.cpearson.com/excel/VBAArrays.htm
musicgold
March 9th, 2010, 01:19 PM
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.
PeejAvery
March 9th, 2010, 02:01 PM
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.
musicgold
March 9th, 2010, 02:51 PM
PeejAvery,
Thanks. Is the form only object that shows its elements in array form?
MG.
HanneSThEGreaT
March 10th, 2010, 12:11 AM
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 :)
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.