The Set is_complete=WebBrowser1. Document. GetElementsByName (" name ") (0)
If Not is_complete Is Nothing Then
MsgBox is_complete
'If WebBrowser1. Document. GetElementsByName (" name ") (0). The Value & lt;> "" Then
The Debug. Print vbLf
The Debug. Print WebBrowser1. Document. GetElementsByName (" name ") (0). The Value
The Debug. Print "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --"
The Debug. Print CCC
End the if
Very tricky question Is entered the if statement after Debug. Print WebBrowser1. Document. The getElementsByName (" name ") (0). The Value of this statement was output Is empty, Is Not is_complete Is Nothing this Is true, then I've tested with Is null & lt;>" Judging "is the same as a result, the first line is the annotation statements and tested, the result is same, access to the object of msgbox output is object htmlinputelement, is sometimes incomplete page load when get the value, can lead to get less than the object, and then an error, so want to pass this statement to determine whether the first loaded completely, but online methods are tested, as well as, judgment is not null, the result won't be able to obtain values, warrior, please give advice or comments? thank you
CodePudding user response:
Really can't add an error handling code:
Sub somesub ()
On error goto hErr
'... Operating the web...
The exit sub
HErr:
The debug. Print err. The description
End sub
Or according to the Document. The ReadyState determine the web:
CodePudding user response:
WebBrowser1. Document. GetElementsByName (" ItemID ") (0). The ValueSo take easy error, because ItemID the array is empty, take a null object Value will be submitted to the null pointer errors,
Should judgment is whether the object is empty, rather than the object's properties for null,
Judge WebBrowser1. Document. GetElementsByName (" ItemID ") is nothing to the next step to False,
In addition, you now is the zeroth element of an array, the problem is not big, if you need to take the first N elements of an array of time, you need to figure out whether the upper bound of the array is bigger than N, otherwise it will cause the array index cross-border errors,