Passing Dictionary object byref

Discussion in 'ASP General' started by Guest, Sep 16, 2003.

  1. Guest

    Guest Guest

    Ive created an ASP class that uses a dictionary object which is filled from a recordset. It passes the object to the propterty of another ASP class byref:

    Public Property Let dicReplaceVars(byref vdicReplaceVars)
    set p_ReplaceVars = vdicReplaceVars
    End Property


    Private p_ReplaceVars


    where it is used in this other class a few times to replace values in an array:

    Function ReplaceVars(vArrayItem)

    '' turn it into an array split at spaces
    vArrayItem = split(vArrayItem," ")
    '' loop through the array
    for count = lbound(vArrayItem) to ubound(vArrayItem)

    ''See if it is a replacement variable and exists in the dictionary
    if left(vArrayItem(count),6) = "tkRep_" and
    p_ReplaceVars.exists(vArrayItem(count)) then
    '' then replace it
    Error occurs here >> vArrayItem(count) =
    p_ReplaceVars.Item(cstr(vArrayItem(count)))
    end if
    next

    dim vArrayItemNew
    vArrayItemNew = ""

    '' Loop through the array and put it back together
    for count = lbound(vArrayItem) to ubound(vArrayItem)

    if vArrayItem(count) = ubound(vArrayItem) then
    vArrayItemNew = vArrayItemNew & vArrayItem(count)
    else
    vArrayItemNew = vArrayItemNew & vArrayItem(count) & " "
    end if
    next

    '' return the vArrayItemNew to the function
    ReplaceVars = vArrayItemNew
    End Function

    The error message I get is:

    ADODB.Field (0x800A0D5C)
    Object is no longer valid. D:\WWW\LCDEV\DOC_FUNCTIONS\../classes/classlcDocTKit_item.asp, line 52

    However I have no idea why, it is a dictionary object and not a recordset, the object should still be open.

    Any help is greatly appreciated.

    Thanks

    -----------------------------
    This message is posted by http://Asp.ForumsZone.com
    Guest, Sep 16, 2003
    #1
    1. Advertising

  2. Guest

    Mark Schupp Guest

    When you set the data into the dictionary object from the recordset make
    sure you use the value. ie:

    rsdata("mycol").value

    not

    rsdata("mycol")

    which returns a field object, not the field's value.


    --
    Mark Schupp
    --
    Head of Development
    Integrity eLearning
    Online Learning Solutions Provider

    http://www.ielearning.com
    714.637.9480 x17


    <> wrote in message
    news:...
    > Ive created an ASP class that uses a dictionary object which is filled

    from a recordset. It passes the object to the propterty of another ASP class
    byref:
    >
    > Public Property Let dicReplaceVars(byref vdicReplaceVars)
    > set p_ReplaceVars = vdicReplaceVars
    > End Property
    >
    >
    > Private p_ReplaceVars
    >
    >
    > where it is used in this other class a few times to replace values in an

    array:
    >
    > Function ReplaceVars(vArrayItem)
    >
    > '' turn it into an array split at spaces
    > vArrayItem = split(vArrayItem," ")
    > '' loop through the array
    > for count = lbound(vArrayItem) to ubound(vArrayItem)
    >
    > ''See if it is a replacement variable and exists in the dictionary
    > if left(vArrayItem(count),6) = "tkRep_" and
    > p_ReplaceVars.exists(vArrayItem(count)) then
    > '' then replace it
    > Error occurs here >> vArrayItem(count) =
    > p_ReplaceVars.Item(cstr(vArrayItem(count)))
    > end if
    > next
    >
    > dim vArrayItemNew
    > vArrayItemNew = ""
    >
    > '' Loop through the array and put it back together
    > for count = lbound(vArrayItem) to ubound(vArrayItem)
    >
    > if vArrayItem(count) = ubound(vArrayItem) then
    > vArrayItemNew = vArrayItemNew & vArrayItem(count)
    > else
    > vArrayItemNew = vArrayItemNew & vArrayItem(count) & " "
    > end if
    > next
    >
    > '' return the vArrayItemNew to the function
    > ReplaceVars = vArrayItemNew
    > End Function
    >
    > The error message I get is:
    >
    > ADODB.Field (0x800A0D5C)
    > Object is no longer valid.

    D:\WWW\LCDEV\DOC_FUNCTIONS\../classes/classlcDocTKit_item.asp, line 52
    >
    > However I have no idea why, it is a dictionary object and not a recordset,

    the object should still be open.
    >
    > Any help is greatly appreciated.
    >
    > Thanks
    >
    > -----------------------------
    > This message is posted by http://Asp.ForumsZone.com
    >
    Mark Schupp, Sep 16, 2003
    #2
    1. Advertising

  3. Guest

    Ryan Malone Guest

    Thank you Mark you are a legend.

    Solved my problem immediately, it was causing all sorts of weird things
    to happen




    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Ryan Malone, Sep 17, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Goncalo

    ByVal and ByRef

    Goncalo, Dec 4, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    6,026
    Dmitriy Lapshin [C# / .NET MVP]
    Dec 4, 2003
  2. Alex Brown

    StateServer pass byref threading problem

    Alex Brown, Apr 21, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    309
    Alex Brown
    Apr 22, 2004
  3. Iams

    Byval vs. byref

    Iams, Feb 24, 2005, in forum: ASP .Net
    Replies:
    5
    Views:
    4,760
  4. xamman
    Replies:
    1
    Views:
    326
    Marina Levit [MVP]
    Dec 22, 2006
  5. Ryan Malone

    Passing Dictionary object byref

    Ryan Malone, Sep 15, 2003, in forum: ASP General
    Replies:
    2
    Views:
    164
    Ryan Malone
    Sep 16, 2003
Loading...

Share This Page