Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Help with paramarray

I have a class with a method that essentially creates a new object of
the same type with the same contents. Since I may want to omit one or
more of the source instance's contents, I have a paramarray argument in
there, and basically, if one of the items exists in the passed array,
it gets skipped and not copied.

Now, I've gone from specifying the excluded items as a list in the
arguments to creating an array of excluded items. I figured that this
would work the same way, but for some reason, the method is getting an
array where the first element is also an array (which is the element I
want).

Here is my crappy code:

Public Function Replicate( _
ParamArray Exclude() As Variant) As Factors

Dim fct As New Factors
Dim lngIndex As Integer
Dim varNames As Variant
Dim varFactors As Variant
Dim varIgnore As Variant

varNames = pDict.Keys
varFactors = pDict.Items
varIgnore = Exclude
For lngIndex = 0 To pDict.Count - 1

If Not IsElementOf(CStr(varNames(lngIndex)), varIgnore) Then

fct.Add CStr(varNames(lngIndex)), CCur(varFactors(lngIndex))

End If

Next lngIndex

Set Replicate = fct

End Function

Any idea what I'm doing wrong?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Help with paramarray

To clarify what the problem is, here's what's happening:

if I call Factors.Replicate("x","y","z"), the paramarray picks up the
correct number of elements. Then I set varIgnore equal to the
paramarray, and if the key is equal to one of the elements of
varIgnore, it's skipped and not copied.

However, if I set varParameters = {"x","y","z"}, then call
Factors.Replicate(varParameters), varParameters is added to the
paramarray instead of being passed AS the paramarray. Thus,
varIgnore(0) = varParameters, and the method can no longer find the
elements of the array that I actually intended as arguments.

MSDN says paramarray should work the same way regardless of whether
you're using a list of arguments or passing it an array, so I have no
idea why this is happening. And unfortunately, it's essential that I
use the array as an argument. I can have the procedure looking at the
elements of varIgnore(0), but that doesn't change the fact that it
shouldn't be storing the array inside varIgnore(0) in the first place.


And really, it makes sense that it would function this way, because it
seems like it should be taking a set of arguments and storing each one
as an element of the paramarray. Is the MSDN page in error, or (more
likely) am I doing something wrong?

Jeremy wrote:
I have a class with a method that essentially creates a new object of
the same type with the same contents. Since I may want to omit one or
more of the source instance's contents, I have a paramarray argument in
there, and basically, if one of the items exists in the passed array,
it gets skipped and not copied.

Now, I've gone from specifying the excluded items as a list in the
arguments to creating an array of excluded items. I figured that this
would work the same way, but for some reason, the method is getting an
array where the first element is also an array (which is the element I
want).

Here is my crappy code:

Public Function Replicate( _
ParamArray Exclude() As Variant) As Factors

Dim fct As New Factors
Dim lngIndex As Integer
Dim varNames As Variant
Dim varFactors As Variant
Dim varIgnore As Variant

varNames = pDict.Keys
varFactors = pDict.Items
varIgnore = Exclude
For lngIndex = 0 To pDict.Count - 1

If Not IsElementOf(CStr(varNames(lngIndex)), varIgnore) Then

fct.Add CStr(varNames(lngIndex)), CCur(varFactors(lngIndex))

End If

Next lngIndex

Set Replicate = fct

End Function

Any idea what I'm doing wrong?


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
ParamArray Jim Chandler[_2_] Excel Programming 4 April 28th 04 03:28 PM


All times are GMT +1. The time now is 07:33 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"