Jump to content
Sign in to follow this  
lafafmentvotre

Find value in array

Recommended Posts

lafafmentvotre

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])

Share this post


Link to post
Share on other sites
lafafmentvotre

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

Share this post


Link to post
Share on other sites
GEOSoft

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

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
Melba23

George,

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

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
jaberwacky

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.

Share this post


Link to post
Share on other sites
GEOSoft

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

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
Melba23

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


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
GEOSoft

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

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
jaberwacky

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

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.