Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Sam Sam is offline
external usenet poster
 
Posts: 2
Default constant array

Is there a way to defind an array of constants in VBA? I
tried the following and it would not compile.

Const a(1) As Double = 1
Const a(2) As Double = 2

Thanks,
Sam
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,089
Default constant array

Sam

one way:

Sub LoadArray()
Dim aA(1 To 5) As Double
Dim i As Long
For i = 1 To UBound(aA)
aA(i) = i
Next 'i
'For i = 1 To UBound(aA)
' Debug.Print i & " " & aA(i)
'Next 'i
End Sub

Regards

Trevor


"Sam" wrote in message
...
Is there a way to defind an array of constants in VBA? I
tried the following and it would not compile.

Const a(1) As Double = 1
Const a(2) As Double = 2

Thanks,
Sam



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default constant array

As I recall, you can't use the Const Keyword with an array.

--
Regards,
Tom Ogilvy

"Sam" wrote in message
...
Is there a way to defind an array of constants in VBA? I
tried the following and it would not compile.

Const a(1) As Double = 1
Const a(2) As Double = 2

Thanks,
Sam



  #4   Report Post  
Posted to microsoft.public.excel.programming
Sam Sam is offline
external usenet poster
 
Posts: 2
Default constant array

Trevor,
Thanks for the suggestion. I want to avoid a call to a
procedure to do this. My specific problem is this: in
calculating the positions of the planets, I have to
evaluate a series of terms in the form A*Cos(B+C*t), where
A, B, and C are constants. This does not look too bad to
code in-line. However, when I have to sum anywhere from 32
to 64 of these, I could save myself a lot of problems if
the constants are in a array. My goal is to load the
constants into the array at compile time and not at run time.

Regards,
Sam
-----Original Message-----
Sam

one way:

Sub LoadArray()
Dim aA(1 To 5) As Double
Dim i As Long
For i = 1 To UBound(aA)
aA(i) = i
Next 'i
'For i = 1 To UBound(aA)
' Debug.Print i & " " & aA(i)
'Next 'i
End Sub

Regards

Trevor


"Sam" wrote in message
...
Is there a way to defind an array of constants in VBA? I
tried the following and it would not compile.

Const a(1) As Double = 1
Const a(2) As Double = 2

Thanks,
Sam



.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 71
Default constant array

The direct answer to your question is No.

You can do this, which is sort of close in a way, kind of but not really.

Sub Main()
Const s As String = "1,2,3,4,5"
Dim v As Variant, i As Integer
v = Split(s, ",")
For i = LBound(v) To UBound(v)
Debug.Print v(i)
Next i
End Sub

"Sam" wrote in message
...
Is there a way to defind an array of constants in VBA? I
tried the following and it would not compile.

Const a(1) As Double = 1
Const a(2) As Double = 2

Thanks,
Sam



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Vlookup - need the array to be constant reesrob Excel Worksheet Functions 2 November 18th 07 02:29 PM
Array Constant? SayWhatAuto Excel Discussion (Misc queries) 2 December 30th 06 02:24 PM
Array formula with a constant? Tester Excel Worksheet Functions 4 October 31st 06 10:44 PM
array formula with constant name Excel Worksheet Functions 2 May 24th 06 05:14 PM
Array constant issue Sige Excel Worksheet Functions 16 March 16th 06 02:56 PM


All times are GMT +1. The time now is 08:10 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"