Sign in to follow this  
Followers 0
Azevedo

Compiling error: ARRAY

13 posts in this topic

Hey everyone!

I've got this error that occurs ONLY when the script is compiled:

"Error: Array variable has incorrect number of subscripts or subscri..."

Here is some discussion but no solutions found.

I compiled with the latest compiler version.

Anyone?

Share this post


Link to post
Share on other sites



That post is over 5 years old, whatever the problem was in that post isn't the same as what's wrong with YOUR script. Post your script because there's absolutely no way to troubleshoot it without knowing what you did wrong.

BTW, there's nothing wrong with the compiler, the problem is in your script.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Thanks. here it goes:

I stripped some parts of the code.

The error happens around

While $rlist[$i] and $esc_control=1 ; and $i<=$max and $i>=0
$esc_control=0
RunWait ( [...] )
WEnd

#include
#include

[...]

$dest = StringReplace($dest,"\front.jpg","")

[...]

Local $cmd = Run($command, "", @SW_HIDE, $STDOUT_CHILD)

While ProcessExists($cmd)
sleep(50)
WEnd

$list = StdoutRead($cmd)
$list = StringSplit($list, @CRLF,1)
;_ArrayDisplay($list)
;global $max = $list[0]-2 ; max entries in the array
_ArrayDelete( $list, $list[0]) ; delete last
_ArrayDelete( $list, 0) ; delete first
$rlist = _ArrayShuffle($list)
;_ArrayDisplay($rlist)

global $i=0
global $esc_control=1
While $rlist[$i] and $esc_control=1 ; and $i<=$max and $i>=0
$esc_control=0
RunWait ( [...] )
WEnd
Exit
[...]

; http://dampeftw.com/autoit-shuffle-or-randomize-and-array/
Func _ArrayShuffle($a_array,$s_start=0,$e_end=-1)

$t_array = $a_array
$t_start = $s_start

If ($e_end<>-1) Then
$t_end = $e_end
Else
$t_end = UBound($t_array)
EndIf

For $ii = $t_start to $t_end
_ArraySwap($t_array[Random($t_start,$t_end)],$t_array[Random($t_start,$t_end)])
Next

Return $t_array

EndFunc

Thanks!

Share this post


Link to post
Share on other sites

For one thing, you're reading the StdOut wrong. You should be reading it in a loop until the program ends, see the example script in StdOutRead for how it's done.

If there's nothing read from the one read of StdOutRead that you're doing, there's nothing to StringSplit, so there's not going to be an array returned from it which will cause array errors all through the rest of the script.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Hey, thanks

Well i've seen the example on the help but it runwait() wont catch the program's output, so i put that while to wait for the program to finish.

It's just a simple array of file list. the script gets the input filelist as a parameter then process it.

After various test with _ArrayDisplay($list) it shows the array as expected and the error will **ONLY** occur when the script is compiled, otherwise it shows no error messages and works as expected.

Share this post


Link to post
Share on other sites

Hey, thanks

Well i've seen the example on the help but it runwait() wont catch the program's output, so i put that while to wait for the program to finish.

What help file are you reading? The one that I have uses Run and not RunWait, because that would be stupid to use RunWait to try and read the StdOut of the program being run.

It's just a simple array of file list. the script gets the input filelist as a parameter then process it.

Use _FileListToArray instead of running an external program, it's much easier. If you need a list of files in subdirectories, then use one of the dozen of recursive versions of it.

Can't help beyond this because your script doesn't run, and I have no idea what you're doing to populate the array.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

problem solved...

the error occurs when the While tries to check $rlist[$i].

if $i outbounds the array limits it will give the error message.

I solved by not using $rlist[$i]:

While $i<=$max and $i>=0

Edited by Azevedo

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

What help file are you reading? The one that I have uses Run and not RunWait, because that would be stupid to use RunWait to try and read the StdOut of the program being run.

Demonstrates StdoutRead()
#include <Constants.au3>

Local $foo = Run(@ComSpec & " /c dir foo.bar", @SystemDir, @SW_HIDE, $STDERR_CHILD + $[color="#ffffff"][background=#3399ff]STDOUT[/background][/color]_CHILD)
Local $line
While 1
$line = StdoutRead($foo)
If @error Then ExitLoop
MsgBox(0, "[color="#ffffff"][background=#3399ff]STDOUT[/background][/color] read:", $line)
WEnd

While 1
$line = StderrRead($foo)
If @error Then ExitLoop
MsgBox(0, "STDERR read:", $line)
WEnd

MsgBox(0, "Debug", "Exiting...")

indeed it is nonsense reading the stdout after the program has finnished.

but It somehow worked for me :)

what i'm reading is a 'DIR /B' output

$command = @ComSpec & " /c dir /b "

Local $cmd = Run($command, "", @SW_HIDE, $STDOUT_CHILD)

While ProcessExists($cmd)
sleep(50)
WEnd

$list = StdoutRead($cmd)
Edited by Azevedo

Share this post


Link to post
Share on other sites

indeed it is nonsense reading the stdout after the program has finnished.

but It somehow worked for me :)

I was referring to the fact that RunWait doesn't return a PID, it returns the exitcode of the program that was run, so StdOutRead wouldn't work with it as it needs the PID.

Also, I tested using StdOutRead after the program has closed, and it DOES work correctly. Not to mention there's no unnecessary blank lines to be dealt with that way. Learn something new everyday. I guess the help file is wrong on that count.

what i'm reading is a 'DIR /B' output

As I said, _FileListToArray would probably be a lot easier to use than Dir and StringSplit.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

_FileListToArray would be my pick IF it supported subfolders like

dir /B /S c:*.dat

Share this post


Link to post
Share on other sites

Azevedo,

Then look at the RecFileListToArray UDF in my sig. :)

M23

P.S. BrewManNH did suggest doing this in post #6:

"Use _FileListToArray instead of running an external program, it's much easier. If you need a list of files in subdirectories, then use one of the dozen of recursive versions of it"


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Azevedo,

Then look at the RecFileListToArray UDF in my sig. :)

M23

P.S. BrewManNH did suggest doing this in post #6:

"Use _FileListToArray instead of running an external program, it's much easier. If you need a list of files in subdirectories, then use one of the dozen of recursive versions of it"

Use _FileListToArray instead of running an external program, it's much easier. If you need a list of files in subdirectories, then use one of the dozen of recursive versions of it.

I missed the lead man, dumb me.

The thing is I'm so used to the simplicity of AutoHotkey, and now I'm finding the differences to AutoIt.

The RecFileListToArray does the work, but the code is too extensive for a simple task.

Then i still pick 'dir /b /s' over it.

Autoit manages arrays much better than Autohotkey does, though.

In both, I'll sometimes have to call for external 3rd party command line tools (like nircmd) to do the job.

I think the thing about scripting languages (batch, autoit, autohotkey, vbs) is the simplicity.

When writing something in C/C++ becomes easier than the script then there is no point to implement a complex scripting code, especially for a simple task like "dir /s /b".

After all, Autoit still the king of scripts :)

Edited by Azevedo

Share this post


Link to post
Share on other sites

Azevedo,

The RecFileListToArray does the work, but the code is too extensive for a simple task

Surely the whole idea of a UDF is that you need not worrry about the code, you just use the functions as if they were built-in? :huh:

Surely a single line (plus the initial #include line) which gives you a nice array:

$aList = _RecFileListToArray("Path", "Mask", 1, 1)

has got to be easier that all that StdoutRead code you posted above? ;)

And if you think reliably recursively searching a folder tree is a simple task, you ought to try it some day. :D

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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  
Followers 0