Professional Web Applications Themes

Returning an Array of Dictionary Objects - ASP Database

Hello, I am trying to write a function that uses .getRows and processes the array into an array of scripting.dictionary obejcts. The problem has been returning the array of dictionary objects. Here's my code: Function getDictFromRecordSet(strQuery, arrFields, intStart, intRows) Dim arrResults Dim rsTemp, dicTemp, i, j Set rsTemp = Server.CreateObject("ADODB.Recordset") With rsTemp .ActiveConnection = Application("ConnStrCatalog") .Source = strQuery .Open arrResults = .GetRows(intRows, intStart, arrFields) .Close End With Set rsTemp = Nothing ReDim dicTemp(UBound(arrResults,2)) For i = 0 To UBound(arrResults,2) Set dicTemp(i) = Server.CreateObject("Scripting.Dictionary") 'Add fields For j = 0 To UBound(arrFields) dicTemp(i).Add arrFields(j), arrResults(i,j) Next Next getArrayFromRecordSet = dicTemp End ...

  1. #1

    Default Returning an Array of Dictionary Objects

    Hello,
    I am trying to write a function that uses .getRows and processes the
    array into an array of scripting.dictionary obejcts. The problem has
    been returning the array of dictionary objects. Here's my code:

    Function getDictFromRecordSet(strQuery, arrFields, intStart, intRows)
    Dim arrResults
    Dim rsTemp, dicTemp, i, j
    Set rsTemp = Server.CreateObject("ADODB.Recordset")

    With rsTemp
    .ActiveConnection = Application("ConnStrCatalog")
    .Source = strQuery
    .Open
    arrResults = .GetRows(intRows, intStart, arrFields)
    .Close
    End With

    Set rsTemp = Nothing

    ReDim dicTemp(UBound(arrResults,2))

    For i = 0 To UBound(arrResults,2)
    Set dicTemp(i) = Server.CreateObject("Scripting.Dictionary")
    'Add fields
    For j = 0 To UBound(arrFields)
    dicTemp(i).Add arrFields(j), arrResults(i,j)
    Next
    Next

    getArrayFromRecordSet = dicTemp
    End Function

    Dim dicResults

    Set dicResults = getDictFromRecordset("SELECT * FROM
    [NaftaItems]",Array("ID","RegionID","Name"),0,10)


    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Dave Guest

  2. #2

    Default Re: Returning an Array of Dictionary Objects

    Do you mind if I ask why on Earth you'd want an array of dictionary
    objects?!

    And also, what does "the problem has been returning the array of dictionary
    objects." mean? Do you get an error of some sort? Do you get unexpected
    results of some sort?

    Ray at work

    "Dave B" <com> wrote in message
    news:phx.gbl... 


    Ray Guest

  3. #3

    Default Re: Returning an Array of Dictionary Objects

    Because an array of dictionary objects will combine a table's column
    names and records all together. I believe the dictionary array is
    populated fine, but it's the "Set dicResults = " statement that kills
    me. The error I'm getting is Object Required ''.

    My other option is just to make 1 dictionary object with names like
    "ID.1", "RegionID.1", "ID.2", "RegionID.2" which I'm not feeling.

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Dave Guest

  4. #4

    Default Re: Returning an Array of Dictionary Objects

    You're antivirus program may be blocking script.
    Dave B wrote: 

    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.


    Bob Guest

  5. #5

    Default Re: Returning an Array of Dictionary Objects

    Hmmm guess this didn't go through the first time.

    I want an array of dic objects because it will perfectly let me
    reference a table's records by record number and column name. The
    problem seems to be at the "Set dicResults = " statement; it gives me an
    Object required '' error. I could but would rather not combine record
    number & column into 1 dictionary object, like dicResults("ID.1")

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Dave Guest

  6. #6

    Default Re: Returning an Array of Dictionary Objects

    You are not returning an object, you are returning an array of objects. Lose
    the "set".

    --
    Mark Schupp
    Head of Development
    Integrity eLearning
    www.ielearning.com


    "Dave B" <com> wrote in message
    news:phx.gbl... 


    Mark Guest

  7. #7

    Default Re: Returning an Array of Dictionary Objects

    Thank you! That's one mistake I'll never make again.

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Dave Guest

  8. #8

    Default Re: Returning an Array of Dictionary Objects

    "Dave B" <com> wrote in message
    news:phx.gbl... 

    [snip]

    This link may be of interest:

    Sorting a Scripting Dictionary Populated with String Data
    http://support.microsoft.com/support/kb/articles/Q246/0/67.ASP


    McKirahan Guest

  9. #9

    Default Re: Returning an Array of Dictionary Objects

    Hmm 1 last question to wrap this up... When I populate the array inside
    the function it is type variant. But as soon as I reference the array
    outside the function it's type empty, and I can't do anything with it...
    what am I doing wrong? Do I need to write this as a COM object instead
    or...

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Dave Guest

  10. #10

    Default Re: Returning an Array of Dictionary Objects

    Blah nevermind, I'm stupid. getDictFromRecordset <>
    getArrayFromRecordset.

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Dave Guest

  11. #11

    Default Re: Returning an Array of Dictionary Objects

    never say never!!

    --
    Mark Schupp
    Head of Development
    Integrity eLearning
    www.ielearning.com


    "Dave B" <com> wrote in message
    news:phx.gbl... 


    Mark Guest

Similar Threads

  1. Replies: 2
    Last Post: September 8th, 11:47 PM
  2. Sending / returning objects
    By Morten in forum ASP.NET Web Services
    Replies: 3
    Last Post: September 13th, 07:09 PM
  3. Returning user-defined objects from a web method
    By Rafael Corchuelo in forum ASP.NET Web Services
    Replies: 0
    Last Post: March 6th, 03:09 PM
  4. #25898 [NEW]: array returning mechanism from objects?
    By sven at leon dot uia dot mx in forum PHP Development
    Replies: 0
    Last Post: October 17th, 05:21 PM
  5. Returning dictionary from a function
    By Ray at in forum ASP
    Replies: 0
    Last Post: September 25th, 02:47 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139