lafafmentvotre Posted May 8, 2010 Posted May 8, 2010 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])
jaberwacky Posted May 8, 2010 Posted May 8, 2010 Always count array elements beginning with the number zero. Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum?
lafafmentvotre Posted May 8, 2010 Author Posted May 8, 2010 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
GEOSoft Posted May 8, 2010 Posted May 8, 2010 (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 May 8, 2010 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 Melba23 Posted May 8, 2010 Moderators Posted May 8, 2010 George,On your hobby-horse again, I see. Remember some of us like counts in the [0] element. M23 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 ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
jaberwacky Posted May 8, 2010 Posted May 8, 2010 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. Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum?
GEOSoft Posted May 8, 2010 Posted May 8, 2010 (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 May 8, 2010 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 Melba23 Posted May 8, 2010 Moderators Posted May 8, 2010 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 Open spoiler to see my UDFs: Reveal hidden contents ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
GEOSoft Posted May 8, 2010 Posted May 8, 2010 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!"
jaberwacky Posted May 8, 2010 Posted May 8, 2010 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 Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum?
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now