Jump to content

[Solved] Subscript used on non-accessible variable


Recommended Posts

Hi Experts,

Hope everyone had a great day😄...

I have a small problem right now Experts concerning this error "Subscript used on non-accessible variable". All I want to know is how can I skip this error type in my For... loop... Next... code and should continue looping until end.

My error:
D:\WorkDIR\Tool\ArchivingTool.au3" (101) : ==> Subscript used on non-accessible variable.:
For $j = 1 To $aLevel2_SubFolders[0]
For $j = 1 To $aLevel2_SubFolders^ ERROR

 

My code:

For $j = 1 To $aLevel2_SubFolders[0]
    _DirRemove($aLevel2_SubFolders[$j], 1)
    GUICtrlSetData($Progress1, $j)
Next

If I'm not mistaken, the loop stop's because the variable is equals to 0 already, and no longer continuing the loop. I tried adding "If @error then ContinueLoop" but I think it's not the right one because still stop's the loop.

From the path declared, I have 23 or more subfolders to remove from a parent folder and some were excluded in removing (was declared in separate line of my code). The problem is, when my first parent folder already has no subfolder/s to remove then my For loop stop running and flagged this error. Can I do something on that? I mean, I need to continue my deletion of subfolders even if the first parent folder is already empty or was already deleted.

Please let me know if you need more explanation, thanks in advance Experts.

 

KS15

Edited by KickStarter15

Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare.

Link to comment
Share on other sites

If it's not an array, then you need to skip that section of code to avoid the subscript error. If that doesn't meet your needs, then perhaps you need to take a step back to determine if you are attempting to fix a symptom rather that the actual problem (ie: what command is creating the array and why is it failing to do so on some occasions?)

Link to comment
Share on other sites

@Danp2, Yup, skipping is the way and what I did is writing a dummy array just to proceed with the loop. Well thanks for sharing IsArray indeed it solved my problem🙂.

Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare.

Link to comment
Share on other sites

@KickStarter15 :

For completeness only : Could you please post an executable minimal script that causes the problem. This may help to identify and solve it as suggested here :

59 minutes ago, Danp2 said:

... to determine if you are attempting to fix a symptom rather that the actual problem (ie: what command is creating the array and why is it failing to do so on some occasions?) 

 

@Nine : Nice usage of the ternary operator.

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

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...