Sign in to follow this  
Followers 0
RvBSvnhO

(Ubound) - 1 - read - 1

17 posts in this topic

#1 ·  Posted (edited)

Hey people, I move for a while with AutoIt. Just who is giving an error that I have never seen yet.

The error is the following:

(Ubound) - 1 contained in the for, is reading the array after then falls over with -1. And coming back with error "Subscript used with non-Array variable."

Why ?

Exemple :

Local $arr1[3] = [ '1', '2', '3']
Local $arr2[3] = ['2', '3', '4']
Local $i
For $i = 0 to UBound($arr1) -1
if _arraySearch($arr2, $arr1[$i]) = -1 then
If _ArraySearch($arr2, $arr1^ ERROR
EndIf
Next

RvB #SvnhO¹

:oops:

Edited by RvBSvnhO

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

The array starts at 0, you are looking for -1 which does not exist

array 0 is usually the number of items in the array, so when you Ubound(array)-1, you are telling it not to use array 0

I glanced over the first 2 lines and didn't register them.

1 thing I noticed is you use _arraySearch

is should be _ArraySearch

you also need to include the array udf (not sure if you are in your main script or not)

other than that, it's working correctly for me.

#Include <Array.au3>
Local $arr1[3] = [ '1', '2', '3']
Local $arr2[3] = ['2', '3', '4']
Local $i
For $i = 0 to UBound($arr1)-1
if _ArraySearch($arr2, $arr1[$i]) = -1 then MsgBox(0,"",@error)
Next

*edit*

#Include <Array.au3>
Local $arr1[3] = [ '1', '2', '3']
Local $arr2[3] = ['2', '3', '4']
Local $i
Local $search
For $i = 0 to UBound($arr1)-1
$search = _ArraySearch($arr2, $arr1[$i])
if $search = -1 then MsgBox(0,"error",@error)
If $search <> -1 Then MsgBox(0,"found",$search)
Next

*edit*

in the 2nd example, you can see that it does not find "1" in array2 (error "6")

it finds "2" in array2 at position 0, and finds "3" in array2 at position 1

then exits because there are no more values in array1

Edited by kaotkbliss

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Share this post


Link to post
Share on other sites

I'm not getting any errors with that script. Although I'm assuming the second If/Then line was showing the error and also assuming you used #include <Array.au3> in the real script somewhere.


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

Yes, that's right.

Only for inside, it reads like Ubound as the size of array and then he falls to -1.

Exemplo :

For $i = 0 to Ubound($Array1)-1
ConsoleWrite(";"Ubound($Array1)-1)
; 2
After
; - 1
Next

Why ?

Share this post


Link to post
Share on other sites

BrewManNH

Yes, the #Include <Array.au3>, is already included.

Share this post


Link to post
Share on other sites

kaotkbliss

Is Erro = 6 , not Array.

As I said earlier in the topic - "Subscript used with non-Array variable."

Share this post


Link to post
Share on other sites

What do you mean it falls to -1, when is this happening? Because it's not happening 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

BrewManNH

Sorry, I got just one example. My script is in StringRegExp, picking up 22 arrays. Only the Ubound is listing to 21 and then goes to -1 giving error in $ i.

Share this post


Link to post
Share on other sites

the array search function returns -1 if the search string is not found otherwise returns the first array element where it is found.

also kaotkbliss

autoit is not case sensitive


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

BrewManNH

Sorry, I got just one example. My script is in StringRegExp, picking up 22 arrays. Only the Ubound is listing to 21 and then goes to -1 giving error in $ i.

use ubound -1 as the limit. not ubound and stringregexp returns a zero based array, not 1 based. that means you have to stop at ubound -1

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

GEOSoft

Yes, I Know.

Except that the error is in the Ubound($Array1) -1 read as 21 and then reads as -1, you should remain at 21. (Inside for)

Edited by RvBSvnhO

Share this post


Link to post
Share on other sites

You're going to need to post a script that demonstrates that, because I've never seen that before, unless you're deleting array elements inside your For loop.


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

#13 ·  Posted (edited)

The variable was equal to the Ubound of the other inside it, why he was reading once, and the second accused was not to be an array in For Loop.

Sorry, people.

I can not believe I did not see iso, you can close the topic.

Thank for much you all.

RvB #SvnhO

:oops:

Edited by RvBSvnhO

Share this post


Link to post
Share on other sites

also kaotkbliss

autoit is not case sensitive

I know, but I find it good practice and have a habit of making sure cases match (just in case) so I see it as an error


010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Share this post


Link to post
Share on other sites

Run Tidy on the script, it will fix those types of "mistakes". :oops:


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

BrewManNH,

Took the words right out of my mouth! :bye:

M23

P.S. Or to be absolutely correct - the keys right off my keyboard! :oops:


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

BrewManNH

Thanks for the tip. ; )

I've got here.

Thank for much you all.

8)

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