Jump to content

What does "Error: Object referenced outside a 'with' statement" mean (and how to fix it)?


ohaya
 Share

Recommended Posts

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

  • Moderators

@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

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 by Juvigy
update
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...