ohaya Posted October 25, 2018 Share Posted October 25, 2018 Hi, I am using _IE functions, and, originally, I had code in the main that was set a local variable, $oForm, to a reference to a form object on a webpage. Now, I wanted to move that code into a function, so I created the function and moved the code into the function, but when I execute the script, I am getting an error: "Error: Object referenced outside a 'with' statement" I am not sure what that error means, and also how to fix it? The code looks like: . . . Func Main() . . Local $oForm . . $oForm = _IEFormGetCollection($oIE, "FORMNAME") . NewFunc($oForm, ...) . EndFunc . . Func NewFunction($refForm,....) . For $i = 0 To $refForm.elements.length Local $sFormElementText = $refForm.elements.item($i).name ^ ---------- ERROR IS POINTING HERE . . Next EndFunc Also, what is the "'with statement'" that the error is talking about? Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted October 25, 2018 Moderators Share Posted October 25, 2018 @ohaya A little difficult to help when you post several unrelated lines of code, with big gaps between them, and then ask us to divine a reason for your error. Please post the entire code, or at least a reproducer that shows the issue, along with the exact wording of the error. Help us help you "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
BigDaddyO Posted October 25, 2018 Share Posted October 25, 2018 without more information, I'm going to take a wild guess and say that the $i item you are referencing doesn't exist $refForm.elements.item($i) so when it tries to do the .name part it's failing. Link to comment Share on other sites More sharing options...
Juvigy Posted October 29, 2018 Share Posted October 29, 2018 (edited) I think the problem is in this line: For $i = 0 To $refForm.elements.length step 1 It has to be either: 1. For $i = 1 To $refForm.elements.length step 1 or 2. For $i = 0 To $refForm.elements.length - 1 step 1 I would say that it is number 1. Edited October 29, 2018 by Juvigy update Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now