Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
Array Question
Thanks for the helpful responses, especially the examples...Ron
|
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
array question | Excel Discussion (Misc queries) | |||
question on Array | Excel Programming | |||
array question | Excel Programming | |||
array question | Excel Programming | |||
Array question | Excel Programming |