Mombu the Programming Forum

Go Back   Mombu the Programming Forum > Programming > len() in 5.2
User Name
Password
REGISTER NOW! Mark Forums Read




Reply
1 19th October 17:56
External User
 
Posts: 1
Default len() in 5.2



Has anyone had an error generated
when the LEN(aArray) command is used to test an array length.
The array is empty when this occurs.
I'm using clipper 5.2. Blinker 5.
The array is PRIVATE aArray := {} in the calling routine.
It is being called in a subsequent routine.

Routine A
PRIVATE aArray := {}
....
if ...
aArray =: ..fill array with values..
endif
....

Routine B
if len(aArray) > 1
do...
endif
....

Thanks for any help if you've experienced this problem.

CWF
  Reply With Quote


 


2 19th October 17:56
valusoft
External User
 
Posts: 1
Default len() in 5.2



Function ArrayLen( aYours )

local i

for i := 1 to len(( aYours )
if aYours[i] == ""
exit
endif
next

Return (i - 1)


Regards,

Ross McKenzie
ValuSoft
Melbourne Australia
  Reply With Quote


 


3 19th October 17:56
ray marron
External User
 
Posts: 1
Default len() in 5.2


[SNIP]

Nope, never. What's the exact error?

--
Ray Marron
  Reply With Quote
4 19th October 17:56
stephen quinn
External User
 
Posts: 1
Default len() in 5.2


cwf

Is the initialisation/declaration of the array done BEFORE the you call Routine B??
Is Routine A listed in the source file BEFORE Routine B??

If you want it to be visible to the whole file then declare it as static BEFORE any other functions.
Eg

STATIC anArray

FUNCTION Main()

anArray := {}
...
RETURN

FUNCTION A()

IF Empty( anArray )
aadd( anArray, { 'A,9,'B', 1 } )
...
ENDIF

FUNCTION B()

--
HTH
Steve Quinn
  Reply With Quote
5 19th October 17:56
gabor salai
External User
 
Posts: 1
Default len() in 5.2


check that you are accessing *target* array, not something else
put "?vartype(aaray)" before len ...
  Reply With Quote
6 19th October 17:56
dave pearson
External User
 
Posts: 1
Default len() in 5.2


* c_w_finch@hotmail.com <c_w_finch@hotmail.com>:

It'd be more useful if you stated *what* error you're getting and on what
line of code. You might also want to think about saying how you know, for
sure, that the array is empty at that time.

--
Dave Pearson | OSLib - Timeslice release functions.
http://www.davep.org/ | eg - Norton Guide reader for Linux.
http://www.davep.org/clipper/ | weg - Norton Guide reader for Windows.
http://www.davep.org/norton-guides/ | dgscan - DGROUP scanner for Clipper.
  Reply With Quote
7 19th October 17:57
news
External User
 
Posts: 1
Default len() in 5.2


This is only useful under a very limited set of conditions. For
example, it won't cope with empty elements, nested arrays or indeed
any array value type that isn't a char. Aside from those limitations,
at it's heart it uses len(aYours), so how is this better than
len(aArray) that the OP is having trouble with?
  Reply With Quote
8 19th October 17:57
valusoft
External User
 
Posts: 1
Default len() in 5.2


Hi Nick,

A minor typing error, hopefully forgiven...try the following. The
function typed hurriedly this morning was meant to show that the len()
ignores empty array elements, whereas mine recognises the first empty
one. And...is not restricted to type char content. So it can be used
to detect the first empty array element in a single dimensioned array.
The OP, in my opinion, was troubled by the apparent result of using
the len() on an empty array. This was an attempt to suggest, albeit
incompletely on my part, that using this function could produce a
better answer. Hope you agree.

Proc main

local aYours := array(5)

aYours[1] := date()
aYours[2] := "Nick"
aYours[3] := .F.
aYours[4] := 12.3

? len( aYours ) // produces 5

? ArrayLen(aYours ) // produces 4

return
*******


Function ArrayLen( aYours )

local i

for i := 1 to len( aYours )
if aYours[i] == NIL //was originally typed as ""
exit
endif
next

Return (i - 1)


Regards,

Ross McKenzie
ValuSoft
Melbourne Australia
  Reply With Quote
9 19th October 17:57
dave pearson
External User
 
Posts: 1
Default len() in 5.2


* valusoft @ mbox.com.au (Ross McKenzie) <valusoft@mbox.com.au>:

Although it isn't at all clear that this is the problem with the OP, is it?

Given the name of the function the result might be confusing given an array
like { 1, "two", 3, nil, 5, "six", nil }.

ObWarning: Looping on LEN( a ) vs storing LEN( a ) to a variable and using
that as the TO value.

ObWhoCanResistShorterCodeTweak:

,----
| Function ArrayLen( a )
| Return( max( 0, ascan( a, NIL ) - 1 ) )
`----

--
Dave Pearson | OSLib - Timeslice release functions.
http://www.davep.org/ | eg - Norton Guide reader for Linux.
http://www.davep.org/clipper/ | weg - Norton Guide reader for Windows.
http://www.davep.org/norton-guides/ | dgscan - DGROUP scanner for Clipper.
  Reply With Quote
10 19th October 17:57
valusoft
External User
 
Posts: 1
Default len() in 5.2


On 23 Oct 2003 12:21:17 GMT, Dave Pearson <davep.news@davep.org>


I guess it is open to interpretation Dave. I took his...

"when the LEN(aArray) command is used to test an array length.
The array is empty when this occurs." in combination with his...
"if len(aArray) > 1" to indicate that the error was an incorrect
reporting of the array....instead of the scoping alternative.
...diversity of viewpoints I guess. Would be interested to hear what
the OP was meaning.


Naming of a function off the top of my head first thing in the morning
is obviously not one of my strong points. Mea culpa.

Had to leave something for others to comment upon <g>.


Yes, I will pay that one....except for the function's name <g>


Regards,

Ross McKenzie
ValuSoft
Melbourne Australia
  Reply With Quote
Reply


Thread Tools
Display Modes




666