Array of constants 
Author Message
 Array of constants


Quote:
> I'm trying to declare a fixed array which values are not
> to be changed. I can declare and assign single variable
> constants. I guess what i'm trying to do is declare and
> assign an array of constants. When i try to do assign the
> values to it I get the error that an equal sign is
> expected at the open parenthesis. Can I do this?? Or is it
> just my imagination??

If I'm understanding correctly....nope...not possible.  You can assign a
constant to an array element, but there's nothing preventing some other
value (of a compatible type) getting assigned to that same array element
later on.

Not sure why this would be an issue, though.  Just make sure your code
doesn't reassign any values to that particular array.

Perhaps if you stated what you were using the array for, someone could
provide you a better alternative.  Posting your code, even though it doesn't
work, would probably give us a pretty good idea of what you're after.
Perhaps an Enum type would suit your purposes?

Mike



Sat, 30 Apr 2005 08:39:05 GMT  
 Array of constants
I'm trying to declare a fixed array which values are not
to be changed. I can declare and assign single variable
constants. I guess what i'm trying to do is declare and
assign an array of constants. When i try to do assign the
values to it I get the error that an equal sign is
expected at the open parenthesis. Can I do this?? Or is it
just my imagination??

Thanks for your advise.

Armando



Sat, 30 Apr 2005 08:14:44 GMT  
 Array of constants

Quote:
> I'm trying to declare a fixed array which values are not
> to be changed. I can declare and assign single variable
> constants. I guess what i'm trying to do is declare and
> assign an array of constants. When i try to do assign the
> values to it I get the error that an equal sign is
> expected at the open parenthesis. Can I do this?? Or is it
> just my imagination??

Strictly speaking, Constants cannot be arrays.

You can get the same runtime functionality by defining a
function that takes an Index value and returns the constant
 value you want assigned to that value.

LFS



Sat, 30 Apr 2005 08:39:18 GMT  
 Array of constants
No one mentioned it yet, so here goes...

You can build an Enum to hold those values.

Public Enum MyConstants
    NoValue = 0
    Const1 = -5
    Const2 = 5
    Const3 = 15
    Const4 = 25
    Infinity = 999999999#
End Enum

(yes, I know infinity can not be expressed as a rational
number, I'm using a little artistic license...)

You gain the advantage of being able to use a real name
with those constants instead of an index into an array
which may (likely) mean nothing to your or anyone else
even as early as tomorrow morning.

Plus, you also get intellisence to help you out with
enums, to (for example) suggest the correct values to
someone using a function with one as a parameter.

Whats easier to read
    Debug.Print MyConstants.Infinity
or
    Debug.Print MyConstants(5)

it's up to you...

D.


Quote:
> I'm trying to declare a fixed array which values are not
> to be changed. I can declare and assign single variable
> constants. I guess what i'm trying to do is declare and
> assign an array of constants. When i try to do assign the
> values to it I get the error that an equal sign is
> expected at the open parenthesis. Can I do this?? Or is it
> just my imagination??

> Thanks for your advise.

> Armando



Sat, 30 Apr 2005 14:48:12 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Array as constant ??

2. Array type constant

3. 2-D array of constants?

4. Setting an array with constant contents

5. Array of constant pointers

6. Creating an array of constants

7. Arrays of Constants on VB, how?

8. an array of constants?

9. Arrays as Constants

10. How declare array of constants ?

11. Array of Constants

12. Creating an array of constants

 

 
Powered by phpBB® Forum Software