Sign in to follow this  
Followers 0
PhilipG

Array problem

4 posts in this topic

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.

Share this post


Link to post
Share on other sites



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 - 1

Ask 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._______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

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

Share this post


Link to post
Share on other sites

Splendid that made my day!

Can't understand why I didn't find it...

Any way: 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  
Followers 0