Jump to content

Recommended Posts

Posted

I everybody and sorry for my english

I wrote a script to find a value in a array column which corresponds to the value of another column but i understand badly arrays

Someone can help me to find and to learn me ?

Thanks

#region AUTOIT VARIABLES
#include <Array.au3>
#endregion
#region SCRIPT VARIABLES
Local $avArray[15][2]=[ _
["COMP01", "#VALUE01"], _
["COMP02", "#VALUE02"], _
["COMP03", "#VALUE03"], _
["COMP04", "#VALUE04"], _
["COMP05", "#VALUE05"], _
["COMP06", "#VALUE06"], _
["COMP07", "#VALUE07"], _
["COMP08", "#VALUE08"], _
["COMP09", "#VALUE09"], _
["COMP10", "#VALUE10"], _
["COMP11", "#VALUE11"], _
["COMP12", "#VALUE12"], _
["COMP13", "#VALUE13"], _
["COMP14", "#VALUE14"], _
["COMP15", "#VALUE15"]]
Local $computer=StringLeft(@ComputerName,6)
#endregion
#region SCRIPT
$sColumn=0
$iPosition=_ArraySearch($avArray, $computer, 0, 0, 0, 1, 1, $sColumn)
MsgBox(0,"",$avArray[$iPosition][2])
Posted

Ahhhhhh ok

Thanks

I change

MsgBox(0,"",$avArray[$iPosition][2])
by
MsgBox(0,"",$avArray[$iPosition][1])

and it works

Thanks for help

#region AUTOIT VARIABLES
#include <Array.au3>
#endregion
#region SCRIPT VARIABLES
Local $avArray[15][2]=[ _
["COMP01", "#VALUE01"], _
["COMP02", "#VALUE02"], _
["COMP03", "#VALUE03"], _
["COMP04", "#VALUE04"], _
["COMP05", "#VALUE05"], _
["COMP05", "#VALUE06"], _
["COMP07", "#VALUE07"], _
["COMP08", "#VALUE08"], _
["COMP09", "#VALUE09"], _
["COMP10", "#VALUE10"], _
["LMC012", "#VALUE11"], _
["COMP12", "#VALUE12"], _
["COMP13", "#VALUE13"], _
["COMP14", "#VALUE14"], _
["COMP15", "#VALUE15"]]
Local $computer=StringLeft(@ComputerName,6)
#endregion
#region SCRIPT
$sColumn=0
$iPosition=_ArraySearch($avArray, $computer, 0, 0, 0, 1, 1, $sColumn)
If @error Then
    MsgBox(0, "Not Found", '"' & $computer & '" was not found on column ' & $sColumn & '.')
Else
MsgBox(0,"",$avArray[$iPosition][1])
EndIf
Posted (edited)

  On 5/8/2010 at 3:20 PM, 'jaberwocky6669 said:

Always count array elements beginning with the number zero.

Unless of course they are 1 based arrays, in which case "Rows" (items) count from 1 and "Columns" (sub-items) from 0.

Hopefully with AutoIt4, if it ever gets written, will come a change to all arrays being 0 based. Just to get it standardized.

Edited by GEOSoft

George

  Reveal hidden contents
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!"

  • Moderators
Posted

George,

On your hobby-horse again, I see. Remember some of us like counts in the [0] element. :idea:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted

  On 5/8/2010 at 4:04 PM, 'GEOSoft said:

Unless of course they are 1 based arrays, in which case "Rows" (items) count from 1 and "Columns" (sub-items) from 0.

Hopefully with AutoIt4, if it ever gets written, will come a change to all arrays being 0 based. Just to get it standardized.

Gosh, I didn't know that they weren't all 0 based! Lurn sumthin' new e'ryday.

Posted (edited)

Only in AutoIt. Take a look at C++ arrays, returns from DLL calls, Delphi arrays, and on and on and on. That is horrid code when there is not at least a standard set, one way or the other. There are only a few functions in AutoIt that return 1 based arrays. Most are 0 based and that is what has to be worked out. I'm not sure of the possibility or feasability og making a change to Ubound() so it actually returns what we now refer to as Ubound() -1. Then if you needed the actuall Ubound(0 of an array, which is rarer, you could use Ubound() +1.

All of the RegExp arrays are Ubound and I very often have to do something like create a new array whose dimension is based on the Ubound() of the array returned from an SRE.

Dim $NewArray[Ubound($oldArray)/2][2]

Followed by a For/Next loop with Step 2.

Besides, how difficult is it for you to add a variable before a loop?

$iUB = Ubound($aArray) -1
For $i = (first element to read) To $iUB

Next

If you need some help I can send you the function that reads a script and replaces all of the

For $i = <number> To $aArray[0]
references to read as
For $i = <number> to Ubound($aArray) -1
Then all you have to do is change a bad habit, undoubtably ingrained in you by some idiotic UDF code. Edited by GEOSoft

George

  Reveal hidden contents
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!"

  • Moderators
Posted

jaberwocky6669,

AutoIt arrays are all 0-based.

GEOSoft is referring to those arrays where there is a counter in the [0] element - like those produced by _FileReadToArray or StringSplit.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted

  On 5/8/2010 at 4:33 PM, 'Melba23 said:

jaberwocky6669,

AutoIt arrays are all 0-based.

GEOSoft is referring to those arrays where there is a counter in the [0] element - like those produced by _FileReadToArray or StringSplit.

M23

Even StringSplit() can return a 0 based array. Just set the flag to 2, which I always do.

George

  Reveal hidden contents
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!"

Posted

  On 5/8/2010 at 4:33 PM, 'Melba23 said:

jaberwocky6669,

AutoIt arrays are all 0-based.

GEOSoft is referring to those arrays where there is a counter in the [0] element - like those produced by _FileReadToArray or StringSplit.

M23

It's all clear now... thanks

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
  • Recently Browsing   0 members

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