Jump to content

Multi-dimensional array, UBound


Recommended Posts

dim $p[10][2] = [["test1","jkldfjghdfjldj"], ["test2", "gdfggdfgfd2"], ["test3", "hgfhgfhf34"], ["test4", "gfhfhfh4"]]
ConsoleWrite(UBound($p)&@crlf) ; returns : 10 as result
ConsoleWrite(UBound($p,0)&@crlf) ; returns : 2 as result
ConsoleWrite(UBound($p,1)&@crlf) ; returns : 10 as result
ConsoleWrite(UBound($p,2)&@crlf) ; returns : 2 as result

Am I totally stupid or this function can't return what I need ? That is, 4 ... the only valuable size of the array I really need to know :)

If I have to fill one-dimension arrays to actually get the size that's dumb..

Link to comment
Share on other sites

Ubound is only going to return the dimensions used when when you Dim or Redim the array, in this case:

dim $p[10][2] = [["test1","jkldfjghdfjldj"], ["test2", "gdfggdfgfd2"], ["test3", "hgfhgfhf34"], ["test4", "gfhfhfh4"]]

You have 10 rows and 2 columns in your Dim but you are only using 4 rows. If you are expecting Ubound($p) to return 4 then use dim $p[4][2]

Link to comment
Share on other sites

Copied and pasted from the helpfile:

UBound ( Array [, Dimension] )

Array The array variable which is being queried.

Dimension [optional] Which dimension of a multi-dimensioned array to report the size of. Default is 1, which is the first dimension. If this parameter is 0, the number of subscripts in the array is returned.

Put your mouse on "Ubound" in scite and hit F1 to read the rest with example.

Link to comment
Share on other sites

I could have figured that.. Let's put it another way :

I want to reserve 10 elements which are couples (x, y) but the array won't be filled all the time and I need the number of couples...

dim $p[10][2]
$p[0][0] = "test1"
$p[0][1] = "gffdjgkldfj"
$p[1][0] = "test2"
$p[1][1] = "tlgfgkldfk"
$p[2][0] = "test3"
$p[2][1] = "jgdfgjkldfjgdfj"

$max = ; here comes the place for a function giving " 3 "

For $i = 0 to $max - 1
    ; script
Next

and no way I'll use one dimension array.. those are results from iniRead(), thus, 2-dimension arrays ... :)

that option in UBound is useless ! OF COURSE we know it's 10 and 2 ... we DEFINED them.. no need for that

Edited by MikeP
Link to comment
Share on other sites

I always has a variable named count or something that I increment everytime I add data, that way I always know how much I have filled my arrays. :)

If UBound was smarter built you wouldn't have to do that.

IniRead() or IniReadSection()? IniReadSection() will return a 2 dimensional array properly sized to the number of key/value pairs in that section.

Yeah sorry I meant iniReadSection. k I guess I'll just declare the variables in the middle of the script which I clearly hate (and get the size in [0][0] whereas I needed them as Global... whatever ... a pity :(
Link to comment
Share on other sites

If UBound was smarter built you wouldn't have to do that.

I wouldn't say that, it's just a shame that you need to declare how big your arrays are going to be at the beginning (since ReDim gets very slow when the array increases), I wonder why we can't have a New[] and Delete[] keywork like in c++?

Broken link? PM me and I'll send you the file!

Link to comment
Share on other sites

You could use an Array, beginning on Index 1. Index 0 would be the Count of filled Lines :( Many UDFs return Arrays in this Format. You just have to rewrite the funcs to add and remove entries :)

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...