aslani 2 Posted September 27, 2007 Is there a function to check if an element exists in an array? Example: $avArray[0] = Start $avArray[1] = Beginning ... $avArray[10] = End $parArray = _ArrayCreate($avArray[2]) ;This one works since $avArray[6] exists, but... If $avArray[6] Then _ArrayAdd($parArray, $avArray[6]) EndIf ; ...if the element doesn't exist, it exits on error rather than simply doing nothing If $avArray[11] Then _ArrayAdd($parArray, $avArray[11]) EndIf [font="Georgia"]Chances are, I'm wrong.[/font]HotKey trouble?Stringregexp GuideAutoIT Current Version Share this post Link to post Share on other sites
SadBunny 131 Posted September 27, 2007 Introduce a check for UBound($myArray). If the element number you want to access is larger than UBound($myArray)-1, it doesn't exist in the array. (FYI: the -1 because UBound always returns one more than the last element number since arrays are 0-based and the [0]'th element also counts.) Something like: If _elementExists($avArray, 11) Then _ArrayAdd($parArray, $avArray[11]) EndIf Func _elementExists($array, $element) If $element > UBound($array)-1 Then Return False ; element is out of the array bounds Return True ; element is in array bounds EndFunc 1 MaxTrax reacted to this Roses are FF0000, violets are 0000FF... All my base are belong to you. Share this post Link to post Share on other sites
aslani 2 Posted September 27, 2007 WOW! I've been trying to figure this out for 2 days and you got it just like that. Thank you! [font="Georgia"]Chances are, I'm wrong.[/font]HotKey trouble?Stringregexp GuideAutoIT Current Version Share this post Link to post Share on other sites
Ober 0 Posted April 15, 2012 How about finding the item inside the array... IE Start, Begining and End -- is there a way to do an "exists" on an array to see if any one of those is in the array or not? in those cases they would all come up true but if you looked for banana you would get false? thanks... Share this post Link to post Share on other sites
Melba23 3,491 Posted April 15, 2012 Ober,Please do not necro-post in topics generally (did you notice the post above yours was made nearly 5 years ago? ), and certainly not in ones that have nothing to do with your question. As to the question itself - if you want to test for the existence of a certain element within an array, then use _ArraySearch. 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: Spoiler 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 Share this post Link to post Share on other sites
Ober 0 Posted April 15, 2012 Sorry, tyvm for answering reguardless... ill try not to do it agian, i didnt even look at the date prior... again sorry and thank you... Share this post Link to post Share on other sites
Melba23 3,491 Posted April 15, 2012 Ober, No problem - just look more closely next time. 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: Spoiler 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 Share this post Link to post Share on other sites