Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
ron ron is offline
external usenet poster
 
Posts: 118
Default Array Question

What are the differences between an array created using the following
method

my_array = Array(100, 200, 300)

and an array created as follows?

my_array(0) = 100
my_array(1) = 200
my_array(2) = 300

I've noticed that the "Filter" function does not work with the array
created by the last construction...TIA, Ron
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default Array Question

The first is a variable holding an array and the second is the array.



"ron" wrote in message
...
What are the differences between an array created using the following
method

my_array = Array(100, 200, 300)

and an array created as follows?

my_array(0) = 100
my_array(1) = 200
my_array(2) = 300

I've noticed that the "Filter" function does not work with the array
created by the last construction...TIA, Ron



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Array Question

My guess is you declared the array as numerical, eg
Dim my_array(0 to 2) as Long

However the Filter function requires a string array (although could be a
variant), so declare your array in one of these ways
Dim my_StrArray(0 to 2) As String
Dim my_VarArray(0 to 2) As Variant

Regards,
Peter T

"ron" wrote in message
...
What are the differences between an array created using the following
method

my_array = Array(100, 200, 300)

and an array created as follows?

my_array(0) = 100
my_array(1) = 200
my_array(2) = 300

I've noticed that the "Filter" function does not work with the array
created by the last construction...TIA, Ron



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 149
Default Array Question

Ron,

If you look at the Help files for Array Function, you'll notice that Array
returns a Variant contining the the arglist. So, the data in that array is
of a Variant data type. If you lookup the Filter Function in the Help files,
you notice that it "returns a zero-based array containing subset of a string
array based on a speicified filter criteria." Furthermore, you'll notice the
the sourcearray is required and should be a "one-dimensional array of STRINGS
to be searched." Additionally, as noted in your example, the array that is
built without the Array Function can be dimensioned to the data type of your
choosing whereas the array built with the Array Function must be a Variant.

I've added some illustrative code below to further bring out the point.
intArr is dimensioned as an Integer and is loaded with Integer type values.
varArr is dimensioned as a Variant and is loaded with Variant type values via
the Array Function. The complier seems to do a String type conversion for
varArr in varArrTest = Filter(varArr, 200) because you do get a result
returned; however, varArrTest = Filter(intArr, 200) does NOT work (i.e. you
will get an error) because intArr contains Integer values, not String values
(as noted in the Filter Function help).

[If you were to change the intArr data type to String (or Variant), instead
of Integer, you would notice that the varArrTest = Filter(intArr, 200) line
would NOT error out; however, if you choose other data types (such as Single,
Double, etc.) you would error out on that line of code].

So, at least two differences between the arrays are (1) being able to
control the data type and (2) sizing the array (explicitly or implicitly).

I hope this helps.

Best,

Matthew Herbert

Sub TestArray()
Dim varArr As Variant
Dim intArr() As Integer
Dim varArrTest As Variant

varArr = Array(100, 200, 300)

ReDim intArr(2)
intArr(0) = 100
intArr(1) = 200
intArr(2) = 300

varArrTest = Filter(varArr, 200)
Debug.Print UBound(varArrTest)

varArrTest = Filter(intArr, 200)
Debug.Print UBound(varArrTest)

End Sub

"ron" wrote:

What are the differences between an array created using the following
method

my_array = Array(100, 200, 300)

and an array created as follows?

my_array(0) = 100
my_array(1) = 200
my_array(2) = 300

I've noticed that the "Filter" function does not work with the array
created by the last construction...TIA, Ron
.

  #5   Report Post  
Posted to microsoft.public.excel.programming
ron ron is offline
external usenet poster
 
Posts: 118
Default Array Question

Thanks for the helpful responses, especially the examples...Ron
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
array question Mona Excel Discussion (Misc queries) 2 March 23rd 10 08:41 PM
question on Array matelot Excel Programming 3 May 10th 07 03:52 PM
array question Brent Excel Programming 4 April 13th 07 11:14 PM
array question Gary Keramidas[_4_] Excel Programming 4 October 4th 05 03:40 AM
Array question Stuart[_5_] Excel Programming 1 August 6th 03 04:13 AM


All times are GMT +1. The time now is 05:09 AM.

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

About Us

"It's about Microsoft Excel"