Jump to content

Lbound Function


ptrex
 Share

Recommended Posts

Hello,

I am missing an Lbound() function in AutoIT.

Is there an alternative arround ?

Or could it be added over time ?

Thanks

Based on the link I found for LBound() which is the opposite of UBound() I dont believe AutoIt needs an LBound() due to all array's starting at 0. The size of an array if I am not mistaken is UBound($array) + 1.

http://www.csidata.com/custserv/onlinehelp...docs/vbs145.htm

I may be speaking out of turn, but as I am pretty sure that AutoIt doesnt allow anything other than 0 for the Lower limit.

JS

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

  • Moderators

Based on the link I found for LBound() which is the opposite of UBound() I dont believe AutoIt needs an LBound() due to all array's starting at 0. The size of an array if I am not mistaken is UBound($array) + 1.

http://www.csidata.com/custserv/onlinehelp...docs/vbs145.htm

I may be speaking out of turn, but as I am pretty sure that AutoIt doesnt allow anything other than 0 for the Lower limit.

JS

It actually would be nice to be able to do something like this:

; The smallest available subscript of the array dimension
$i = LBound($array)
; The upper limit of the array dimension
$z = UBound($array)

For $i To $z
    ; Do something
Next
Link to comment
Share on other sites

It actually would be nice to be able to do something like this:

; The smallest available subscript of the array dimension
$i = LBound($array)
; The upper limit of the array dimension
$z = UBound($array)

For $i To $z
    ; Do something
NextoÝ÷ Ûú®¢×ºw^®ËZÜ!z·²¢æ«yÊ&x®·
.Ùë(ëax,i¸­y«"z·(uçâÅ«­¢+Ø(ÀÌØíèôU  ½Õ¹ ÀÌØíÉÉä¤()½ÈÀÌØí¤ô1  ½Õ¹ ÀÌØíÉÉä¤Q¼ÀÌØíèMÑÀÄ(í¼Í½µÑ¡¥¹ÕÍÕ°)9áÐ

You are required for some reason to assign a value to the variable in the For...Next statement.

JS

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

I'm not seeing the point, really. But my question is, if the function is missing, why are you telling us, why aren't you writing a user-defined function to do it?

Valik

It' s not a big deal to write a UDF for it, but it's not consistant with the Ubound () is it ?

Ubound is not a UDF or am I mistaken, so why should the other one be one ?

Anyhow if you don't like the opposite of Ubound (), let it be for my part.

But I am wondering there are that many functions and macro's available, why would this one hurt anyone ?

Edited by ptrex
Link to comment
Share on other sites

  • Moderators

I assumed after reading it on MSDN it was something like:

Dim $Array[3]
$Array[2] = 15
$Lbound1 = _Lbound($Array, 0)
ConsoleWrite('Attempt 1' & @LF & 'Element ' & $Lbound1 & ' = ' & $Array[$Lbound1] & @LF) ; with making their own array, some use [0] as a value
;;;
$aString = StringSplit('abcdefg', '')
$Lbound2 = _Lbound($aString)
ConsoleWrite('Attempt 2' & @LF & 'Element ' & $Lbound2 & ' = ' & $aString[$Lbound2] & @LF)
;;;
Func _Lbound(ByRef $aArray, $iStart = 1)
    For $iCount = $iStart To UBound($aArray) - 1
        If $aArray[$iCount] <> '' Then Return $iCount
    Next
    SetError(1)
    Return 0
EndFunc
Am I off base here? Of course Return 0 could be an issue IMO.

Edit:

SetError(1) ... :)

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Various random points:

  • Larry is right, if the goal is return the first non-empty element, then it is not the opposite of UBound(). UBound() always returns the size of the array which can also be thought of as one past the last element.
  • What constitutes empty? For a string "" could be empty or "EMPTY" could be empty or...
  • What does it matter if the function is built-in or provided via a user-defined function? As long as the function does what it is supposed to, be happy.
  • People will use LBound() wrong with arrays returned from functions (like StringSplit() versus arrays created manually. In the former case, the actual content starts at element 1 because element 0 is reserved for specifying the size of the array. In the latter case, the real content probably starts at element 0.
There's no real need for AutoIt to have this function built in. For one thing, there are a lot of areas for contention over how the function should behave. It would be best if you just write a function to serve the purpose you need it for and call it good.
Link to comment
Share on other sites

  • Moderators

Various random points:

  • Larry is right, if the goal is return the first non-empty element, then it is not the opposite of UBound(). UBound() always returns the size of the array which can also be thought of as one past the last element.
  • What constitutes empty? For a string "" could be empty or "EMPTY" could be empty or...
  • What does it matter if the function is built-in or provided via a user-defined function? As long as the function does what it is supposed to, be happy.
  • People will use LBound() wrong with arrays returned from functions (like StringSplit() versus arrays created manually. In the former case, the actual content starts at element 1 because element 0 is reserved for specifying the size of the array. In the latter case, the real content probably starts at element 0.
There's no real need for AutoIt to have this function built in. For one thing, there are a lot of areas for contention over how the function should behave. It would be best if you just write a function to serve the purpose you need it for and call it good.
That was the concern I had for Return 0... I personally stay away from giving [0] a value with my made arrays, but it's not as easy to use unless you know that your elements start at 1 or 0 depending on the function you use (StringRegExp() could return [0] as a value as in example).

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

If a function was called LBound then it should look like this

func LBound( ByRef $aArray )
    if( isArray($aArray) ) Then Return 0
    else return -1
endfunc

You want a

_FindFirstElementNotEqualTo( $EmptyString )

but if you want that then you should make a

_FindLastElementNotEqualTo( $EmptyString )

as well, then they'd both be UDF's.

Link to comment
Share on other sites

Thanks all for the feedback.

I don' t understand why you all make so much "fuss" about this Lbound function ?

If it

sounds like sloppy coding

or

I'm not seeing the point, really.

Why do a lot of language have this function available ?

VBS, VB(A), PHP, C#, C++, JScript, ASP, PLSQL, .Net, Java, ...

But OK I know AutoIT is superior :)

Maybe the developers of the other languages where not that clever. :(

Who cares. If you think this is over the top, let it be and we can continue with our lives.

I will call Bill Gates right away, to tell him to remove this "superfluous" function from the languages he is distributing. LOL

PS; I' ve even seen that some languages have even "rBound". But don't panic I will start an other topic for this !?

Edited by ptrex
Link to comment
Share on other sites

Why do a lot of language have this function available ?

VBS, VB(A), PHP, C#, C++, JScript, ASP, PLSQL, .Net, Java, ...

The reason why other languages have a LBound() function is they allow you to define even the first element of the array. Eg: In VB you can define an array with

Dim A(2 To 100)

Where the array starts from 2 and using A(1) would generate an error.

In such conditions, having a LBound function is useful.

In AutoIt, an array always starts from 0 and as such a LBound() function is not required.

Link to comment
Share on other sites

@tonedef

Thanks for pointing this out.

Maybe we should think of implementing an non zero based Array function ?

Basically the reason I raised this topic, is that I am doing a lot of VB(A) and VBS conversions to AutoIT.

And I always run into this Lbound function.

Any Valik pointed out he is not interested, so I will have to do with what there is at the moment.

CU all later.

I have an other question that I want to rease. But I will start a new topic.

Link to comment
Share on other sites

dim $array[30]

$array[25] = "lool"

:D now it starts at 25 other b4 are ""

No, the array starts at 0, the element[25] just happens to contain non-empty data. There is a difference.
Link to comment
Share on other sites

  • 3 weeks later...

I wrote the UBound function to give the size of array dimensions. UBound($array,0) will tell the number of dimensions (something that VB's UBound does not do). Because all arrays in AutoIt start with element 0, even if some people do not want to use the first element, I saw no point in creating LBound; it would always be returning 0.

As for changing the array dimensioning to allow it to start at something other than 0, there are some non-insignificant performance and memory penalties in implementing that. Also, the array dimensioning routine would need a major rewrite to implement it. As a workaround, if you want to use only elements 20 to 40, then define elements 0-20 and subtract 20 from the elment number prior to referencing.

I have plans on some other changes I would like to make to the array system after the next release, now that I have some time :D:D but I have some bugs fixes to do first. I do not expect LBound to be part of those changes.

Edit: fox spelling errors.

Edited by Nutster

David Nuttall
Nuttall Computer Consulting

An Aquarius born during the Age of Aquarius

AutoIt allows me to re-invent the wheel so much faster.

I'm off to write a wizard, a wonderful wizard of odd...

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