PhilipG Posted December 30, 2009 Share Posted December 30, 2009 This is probably a simple one... But i haven't managed to find the answer in the help file. I have also tried finding something in the forum but with no success... Problem: Is there anyway to find out witch the highest Array index is? the problem is i need to be able to calculate how many "rows" the array contains... Any hint? I'm still quite new to this. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 30, 2009 Moderators Share Posted December 30, 2009 PhilipG,The function you are looking for is UBound.But be careful - it returns the total number of elements in th earray, so the highest element is one less than the value you get:Global $aArray[3] ; So we have elements [0], [1], [2] $iTotalElements = UBound($aArray) MsgBox(0, "UBound", $iTotalElements) ; So the highest element is $iTotalElements - 1Ask if anything is unclear. 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 Link to comment Share on other sites More sharing options...
99ojo Posted December 30, 2009 Share Posted December 30, 2009 Hi, UBound might be the function you are looking for, if the array is fullfilled. Keep also in mind, if the array is filled by a function, the first element could hold the amount of elements in the array. If not, you have to loop over array and count by yourself. #include <array.au3> Dim $myarray [5] = [4,0,0,0,0] MsgBox (0,"Array with 1st element holding amount", $myarray [0]) Dim $myarray [5] = [0,0,0,0,0] MsgBox (0,"Array fullfilled", UBound ($myarray)) Dim $myarray [10] = [0,0,0,0,0] $count = 0 For $i = 0 To UBound ($myarray) - 1 If String ($myarray [$i]) <> "" Then $count += 1 Next _ArrayDisplay ($myarray, "Array with empty slots") MsgBox (0, "Array with empty slots", "Filled: " & $count & @CRLF & "Size: " & UBound ($myarray)) ;-)) Stefan Link to comment Share on other sites More sharing options...
PhilipG Posted December 30, 2009 Author Share Posted December 30, 2009 Splendid that made my day! Can't understand why I didn't find it... Any way: Thanks! Link to comment Share on other sites More sharing options...
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