CaptainSparky Posted June 8, 2015 Posted June 8, 2015 (edited) So I was looking everywhere about getting an array's number of slots in use... and found nothing.Is this even possible? for exampleGlobal $array[5]$array[1] = "1 slot in use"$arrayslotsinuse = ArrayGetSlotsInUse($array)Thanks in advance ...I tried making a counter but didn't work so well.. (it crashed app) Edited June 8, 2015 by TheNewHunter Hello. If in someway I have helped, please consider liking my post(s). The formula for the right answer: You + Right Question = Answer (Think) BEFORE you post.
Moderators Melba23 Posted June 8, 2015 Moderators Posted June 8, 2015 TheNewHunter,UBound will tell you how many elements are in the array, but not how many are "in use" - often the coder uses the [0] element to keep a count as the array fills.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
CaptainSparky Posted June 8, 2015 Author Posted June 8, 2015 Yea how many elements, great, thanks! Hello. If in someway I have helped, please consider liking my post(s). The formula for the right answer: You + Right Question = Answer (Think) BEFORE you post.
ViciousXUSMC Posted June 8, 2015 Posted June 8, 2015 Was going to say UBound() as well. And of course if you did have blank elements run _ArrayDelete() first to clean them up. Melba actually has an example of that here: https://www.autoitscript.com/forum/topic/132027-array-delete-blank-element/
javiwhite Posted June 8, 2015 Posted June 8, 2015 If you're looking to include a counter, I would suggest creating a function for adding data to your array.ReDim is your friend here! Example;#Include<Array.au3> ;Used to display results (_ArrayDisplay) local $array[1] ; Initialise the array ;Now lets add something to it AddValueToArray($array,"Dave") AddValueToArray($array,"Phil") AddValueToArray($array,"Jake") _ArrayDisplay($Array) ;Show Results ;Now lets remove Phil, But we want our counter and array to remain neat RemValueFromArray($array,"Phil") _ArrayDisplay($Array) ;Show Results func AddValueToArray( byRef $iArray,$iValue) local $uBound = uBound($iArray,1) ;Get max element number of array reDim $iArray[$uBound + 1] ;Re Dimension the array, Without removing information $Array[$uBound] = $iValue ; Add the new value $Array[0] += 1 ; Increment the counter by 1 EndFunc Func RemValueFromArray( byRef $iArray,$iValue) local $tArray = $iArray ;Store data in a temporary array Dim $iArray[1] ;Reset the array to empty (so we can rebuild it) for $i = 1 to $tArray[0] ;Loop through temporary array if $tArray[$i] = $iValue then ContinueLoop ;We've found the remove value! Lets continue the loop and ignore it. AddValueToArray($iArray,$tArray[$i]) ;The above line was false, So we can run the AddValueToArray Command to add the data Next ;Continue the for loop EndFuncCheersJavi give a man an application, and he'll be frustrated for the day, Teach him how to program applications and he'll be frustrated for a lifetime.
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