negative array index 
Author Message
 negative array index

Hi there folks,
does someone know, how I can realize in RealBasic
an array, that first index is "-1" ?!?

A good example for it would be the
ListBox-class in RealBasic:

there exists the property "Column",
and if you set it, like:

me.Column(-1).UserResizable = TRUE

you have set ALL columns of this ListBox to

UserResizable = TRUE

I wanna make sth. like that...
Any clue ?

Regards

Lorenz Hipp



Wed, 10 Aug 2005 06:40:35 GMT  
 negative array index

Quote:

> there exists the property "Column",
> and if you set it, like:

> me.Column(-1).UserResizable = TRUE

This works because Column is actually a function, not a property.
(Most properties in built-in RB classes are actually implemented as
functions.)  You cannot use a negative index in an array.


Wed, 10 Aug 2005 06:55:26 GMT  
 negative array index
Thomas Reed schrieb:

Quote:


>>there exists the property "Column",
>>and if you set it, like:

>>me.Column(-1).UserResizable = TRUE

> This works because Column is actually a function, not a property.
> (Most properties in built-in RB classes are actually implemented as
> functions.)  You cannot use a negative index in an array.

I thought so; so I guess there is no possibility for me, to implement
a function in that way in my class, that I can use the same syntax, like
me.Column(-1).UserResizable = TRUE
, isn't it ?!?

Regards

Lorenz Hipp



Sat, 13 Aug 2005 16:56:16 GMT  
 negative array index

Quote:

> Thomas Reed schrieb:


> >>there exists the property "Column", and if you set it, like:

> >>me.Column(-1).UserResizable = TRUE

> > This works because Column is actually a function, not a property. (Most
> > properties in built-in RB classes are actually implemented as
> > functions.)  You cannot use a negative index in an array.

> I thought so; so I guess there is no possibility for me, to implement
> a function in that way in my class, that I can use the same syntax, like
> me.Column(-1).UserResizable = TRUE
> , isn't it ?!?

That depends on your class. If your class has a public array property,
then you can't easily have special array values like ListBox has for
Column.

If, on the other hand, you have accessor methods which operate on a
private array property, then you can give any parameter any special
meaning you want to. In the example, passing -1 to Column means you're
referring to all columns in the listbox, and this is a special meaning
made possible by accessor methods.

However, this is *bad design.* Why should I have to remember to pass -1,
a completely arbitrary number, to an array accessor method which is
documented to return a single ListColumn? A better solution would be to
give special cases their own methods. For the ListBox, there should be
an unambiguously-named method like AllColumns that works just like
Column(-1). This would yield more readable code, fewer boundary errors,
and fewer backward-compatibility headaches down the road.

So, if your array property is public, make it private and give your
class meaningful accessor methods. You'll thank yourself later.

HTH.



Sun, 14 Aug 2005 06:52:18 GMT  
 negative array index
Paul Mitchum schrieb:

Quote:
> That depends on your class. If your class has a public array property,
> then you can't easily have special array values like ListBox has for
> Column.

> If, on the other hand, you have accessor methods which operate on a
> private array property, then you can give any parameter any special
> meaning you want to. In the example, passing -1 to Column means you're
> referring to all columns in the listbox, and this is a special meaning
> made possible by accessor methods.

> However, this is *bad design.* Why should I have to remember to pass -1,
> a completely arbitrary number, to an array accessor method which is
> documented to return a single ListColumn? A better solution would be to
> give special cases their own methods. For the ListBox, there should be
> an unambiguously-named method like AllColumns that works just like
> Column(-1). This would yield more readable code, fewer boundary errors,
> and fewer backward-compatibility headaches down the road.

> So, if your array property is public, make it private and give your
> class meaningful accessor methods. You'll thank yourself later.

> HTH.

yeah, that's what I wanted to do from the beginning, but when I saw, that
my class could be good for other users, and looked on that Property/Method
of RBs ListBox, I thought, other users could use it better, if I would
design
my class like the RB's built-in...

OK, thanks-a-lot, I will do it with normal methods.

Best regards,
Lorenz



Tue, 16 Aug 2005 03:49:03 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Negative array indices

2. question about negative indices in fortran 77

3. question about negative indices in fortran 77

4. Built-in func to calculate negative indices??

5. Q : legacy of negative index

6. RubyChangeRequest #U002: new proper nameforHash#indexes, Array#indexes

7. RubyChangeRequest #U002: new proper namefor Hash#indexes, Array#indexes

8. finding 1d index in 2d array of indices

9. Index Values of an Array inside a Cluster inside an Array

10. array as index to array

11. how to access arrays with variable for array names and index

12. automatic arrays with negative size in g95 and gfortran

 

 
Powered by phpBB® Forum Software