Jump to content
Sign in to follow this  
Phenom

subscript used with non-array variable

Recommended Posts

Phenom

I have a compiled AutoIt program which works sometimes, and sometimes doesn't. When it crashes it says, Line 7749 Error : Subscript used with non-array variable. What are the possible causes for this? It used to work, so I don't think the problem is in the code. I checked the amount of free memory I have and it should be sufficient.

Edited by Phenom

Share this post


Link to post
Share on other sites
water

I have a compiled AutoIt program which works sometimes, and sometimes doesn't. When it crashes it says, Line 7749 Error : Subscript used with non-array variable. What are the possible causes for this? It used to work, so I don't think the problem is in the code. I checked the amount of free memory I have and it should be sufficient.

The problem is that you try to access a non-array variable like an array.

I have experienced this kind of problem when you call a function that returns an array on success but an empty string on error (and sets @error).

In this case either check @error after the function call (best choice) or use "IsArray" to check the return value.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
MvGulik

... check @error after the function call (best choice) or use "IsArray" to check the return value.

Checking for @error value is indirect. Using IsArray() is direct.

Better to use direct checkups. Especially when trying to track down the source of a active problem.

---

Phenom,

Start dropping "If Not IsArray($YourArray) Then Exit 991/992/etc" lines after code line that assign data to that array variable. (or if your running your code in script mode, use "... Exit @ScriptLineNumber")

Look for "$YourArray = ..." and "function(..., Byref $YourArray, ...)" cases.

Edited by MvGulik

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Share this post


Link to post
Share on other sites
water

Checking for @error value is indirect. Using IsArray() is direct.

Better to use direct checkups. Especially when trying to track down the source of a problem.

I assume a correctly written function that sets @error if an error occurred.

So I think first checking if an error occurred and if @error=0 then process the returned data is good programming practice.

But I could be wrong ;)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
MvGulik

I assume a correctly written function that sets @error if an error occurred.

So I think first checking if an error occurred and if @error=0 then process the returned data is good programming practice.

But I could be wrong ;)

"good programming practice": I agree.

"assume a correctly written function" on someone else his (unkown) used code. ... Unsafe at best. :)


"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Share this post


Link to post
Share on other sites
water

"assume a correctly written function" on someone else his (unkown) used code. ... Unsafe at best. ;)

Sometimes I'm a bit too optimistic ;)

As we haven't seen the OPs code he can either enhance his own functions or use belt and suspenders to be sure he is on the safe side :)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
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
Sign in to follow this  

×