Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi,
dimensioning a scalar variable and declaring its data type in VBA is no problem: Dim a As Double What if I want the variable to hold an array with multiple components, all with Double precision? This doesn't seem to work: Dim a As Double a = Array() ReDim a(2) Thanks a lot for suggestions! Tom |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Tom,
Dim a() As Double ReDim a(10) For i = LBound(a) To UBound(a) a(i) = i *i Debug.Print i, a(i) Next i HTH " wrote: Hi, dimensioning a scalar variable and declaring its data type in VBA is no problem: Dim a As Double What if I want the variable to hold an array with multiple components, all with Double precision? This doesn't seem to work: Dim a As Double a = Array() ReDim a(2) Thanks a lot for suggestions! Tom |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
let me expand on Topper's reply
if you know the bounds beforehand you create a fixed size array as follows: dim adFixed(1 to 10) as double dim adFixed#(1 to 10) dim adFixed(1 to 10,1 to 4) as double dim adFixed#(1 to 10,1 to 4) if you do not specify a lowerboundary the lowerbound is 0 unless the module has Option Base 1 e.g. dim adFixed(10) as double dim adFixed#(10) if you need to dynamically dimension your array in code: you use redim. redim asDyna$(rowsize,colsize) initializing the empty array (dim asDyna() as string) at the beginning of the procedure is not required, although i always to it for code readability -- keepITcool | www.XLsupport.com | keepITcool chello nl | amsterdam Toppers wrote : Tom, Dim a() As Double ReDim a(10) For i = LBound(a) To UBound(a) a(i) = i *i Debug.Print i, a(i) Next i HTH " wrote: Hi, dimensioning a scalar variable and declaring its data type in VBA is no problem: Dim a As Double What if I want the variable to hold an array with multiple components, all with Double precision? This doesn't seem to work: Dim a As Double a = Array() ReDim a(2) Thanks a lot for suggestions! Tom |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thanks. A more thoughtful reply than my own!
"keepITcool" wrote: let me expand on Topper's reply if you know the bounds beforehand you create a fixed size array as follows: dim adFixed(1 to 10) as double dim adFixed#(1 to 10) dim adFixed(1 to 10,1 to 4) as double dim adFixed#(1 to 10,1 to 4) if you do not specify a lowerboundary the lowerbound is 0 unless the module has Option Base 1 e.g. dim adFixed(10) as double dim adFixed#(10) if you need to dynamically dimension your array in code: you use redim. redim asDyna$(rowsize,colsize) initializing the empty array (dim asDyna() as string) at the beginning of the procedure is not required, although i always to it for code readability -- keepITcool | www.XLsupport.com | keepITcool chello nl | amsterdam Toppers wrote : Tom, Dim a() As Double ReDim a(10) For i = LBound(a) To UBound(a) a(i) = i *i Debug.Print i, a(i) Next i HTH " wrote: Hi, dimensioning a scalar variable and declaring its data type in VBA is no problem: Dim a As Double What if I want the variable to hold an array with multiple components, all with Double precision? This doesn't seem to work: Dim a As Double a = Array() ReDim a(2) Thanks a lot for suggestions! Tom |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hello,
thanks a lot for your quick and very helpful responses! There are still two things I am struggling with: 1) I want to do this: v = Array() ReDim v(2) v(0) = Array(0, 0, 0) But I cannot see a way to declare the values at the level of v(0)(0) as Single, Double, etc. 2) In the following code I dimension an Array of doubles as suggested. Sub Main() Dim foo(0 To 3) As Double foo = bar() End Sub Function bar() As Double bar = Array(0.1, 0.2, 0.3) End Function But I am getting a 'Can't assign to variable' error. If I can return an array, why is it not possible to assign it as such? Your help is very much appreciated! Tom |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
One way:
Dim v() As Double Vdouble = Array(1.2, 3.4, 6.5) ReDim v(2) For i = 0 To 2 v(i) = Vdouble(i) next i Next " wrote: Hello, thanks a lot for your quick and very helpful responses! There are still two things I am struggling with: 1) I want to do this: v = Array() ReDim v(2) v(0) = Array(0, 0, 0) But I cannot see a way to declare the values at the level of v(0)(0) as Single, Double, etc. 2) In the following code I dimension an Array of doubles as suggested. Sub Main() Dim foo(0 To 3) As Double foo = bar() End Sub Function bar() As Double bar = Array(0.1, 0.2, 0.3) End Function But I am getting a 'Can't assign to variable' error. If I can return an array, why is it not possible to assign it as such? Your help is very much appreciated! Tom |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
You can only assign arrays to a variant variable. Otherwise, you can't
assign an array to an array. Sub Main() Dim foo(0 To 3) As Variant foo(0) = bar() For i = LBound(foo(0)) To UBound(foo(0)) Debug.Print foo(0)(i), TypeName(foo(0)(i)) Next End Sub Function bar() As Variant bar = Array(0.1, 0.2, 0.3) End Function -- Regards, Tom Ogilvy wrote in message oups.com... Hello, thanks a lot for your quick and very helpful responses! There are still two things I am struggling with: 1) I want to do this: v = Array() ReDim v(2) v(0) = Array(0, 0, 0) But I cannot see a way to declare the values at the level of v(0)(0) as Single, Double, etc. 2) In the following code I dimension an Array of doubles as suggested. Sub Main() Dim foo(0 To 3) As Double foo = bar() End Sub Function bar() As Double bar = Array(0.1, 0.2, 0.3) End Function But I am getting a 'Can't assign to variable' error. If I can return an array, why is it not possible to assign it as such? Your help is very much appreciated! Tom |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Declaring one bidimensinal Array | Excel Programming | |||
Declaring variable as a dynamic array? | Excel Programming | |||
declaring a public array | Excel Programming | |||
Q: Declaring a dynamic array | Excel Programming | |||
declaring an array of CheckBox's | Excel Programming |