Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > Dictionary Issue

Reply
Thread Tools

Dictionary Issue

 
 
CJM
Guest
Posts: n/a
 
      01-31-2006
I'm using a dictionary to record some totals, however, my first attempt
failed and I wasnt sure why...

snippet from original code:

oTotalFilters.Item(rsNetStock.fields("PartNo")) =
oTotalFilters.Item(rsNetStock.fields("PartNo") ) + CInt(iNumFilters)


After going back to the start, I eventually realised that the dictionary
Item property didn't like 'rsNetStock.fields("PartNo")' as a parameter, so I
had to use something like the following:

sTest = rsNetStock.fields("PartNo")
oTotalFilters.Item(sTest) = oTotalFilters.Item(sTest) + CInt(iNumFilters)

Am I missing something here? Surely, my original code should have worked?

Is this a known bug/feature?

Thanks

CJM

--

[remove the obvious bits]


 
Reply With Quote
 
 
 
 
Tim Slattery
Guest
Posts: n/a
 
      01-31-2006
"CJM" <> wrote:

>I'm using a dictionary to record some totals, however, my first attempt
>failed and I wasnt sure why...
>
>snippet from original code:
>
>oTotalFilters.Item(rsNetStock.fields("PartNo")) =
>oTotalFilters.Item(rsNetStock.fields("PartNo") ) + CInt(iNumFilters)
>
>
>After going back to the start, I eventually realised that the dictionary
>Item property didn't like 'rsNetStock.fields("PartNo")' as a parameter,


No reason it shouldn't like that. The argument to "item" is expected
to be a character string. The statement you give above assumes that
there is already something stored under that string, otherwise there
would be nothing to retrieve and add to.


> so I
>had to use something like the following:
>
> sTest = rsNetStock.fields("PartNo")
>oTotalFilters.Item(sTest) = oTotalFilters.Item(sTest) + CInt(iNumFilters)
>
>Am I missing something here? Surely, my original code should have worked?


What were you expecting to happen? What happened instead?

--
Tim Slattery
MS MVP(DTS)

 
Reply With Quote
 
 
 
 
CJM
Guest
Posts: n/a
 
      01-31-2006

"Tim Slattery" <> wrote in message
news:...
>>
>> sTest = rsNetStock.fields("PartNo")
>>oTotalFilters.Item(sTest) = oTotalFilters.Item(sTest) + CInt(iNumFilters)
>>

>
> What were you expecting to happen? What happened instead?
>


I was expecting the dictionary item to be updated.

When I retrieve the dictionary items later they were all 0. The reason why
is that 'oTotalFilters.Item(rsNetStock.fields("PartNo")) ' resolved to null
(whereas 'oTotalFilters.Item(sTest)' resolved to the appropriate value.



 
Reply With Quote
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      02-01-2006
Hi CJM,

For Vbscript, it is dynamic script which use late binding, and the type of
the objects used in script are validated at runtime. For your scenario, is
the rsNetStock an ADO.RecordSet? If so, the RecordSet.fields(key) return
a ADO field object, not directly the value. While we simply assign it to a
variable like

dim id = rsRecords.Fields("id")

that's ok. However, if we directly pass it to the dictionary object's Add
method or key/value accessor, the runtime engine will fail to parse the
object. If you do not want to use additional temp variable, you need to
explicitly use the "Value" property to access the data value of each field
in record row. e.g:

=========================
while not myRS.EOF

Response.Write("<br/>CategoryName: " & myRS("CategoryName"))


list(myRS.Fields("CategoryID").Value) = myRS.Fields("CategoryName").Value &
" value"


myRS.MoveNext()

wEnd
========================

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

 
Reply With Quote
 
CJM
Guest
Posts: n/a
 
      02-01-2006

"Steven Cheng[MSFT]" <> wrote in message
news:...
> Hi CJM,
>
> For Vbscript, it is dynamic script which use late binding, and the type of
> the objects used in script are validated at runtime. For your scenario, is
> the rsNetStock an ADO.RecordSet? If so, the RecordSet.fields(key) return
> a ADO field object, not directly the value. While we simply assign it to a
> variable like
>
> dim id = rsRecords.Fields("id")
>
> that's ok. However, if we directly pass it to the dictionary object's
> Add
> method or key/value accessor, the runtime engine will fail to parse the
> object. If you do not want to use additional temp variable, you need to
> explicitly use the "Value" property to access the data value of each field
> in record row. e.g:
>
> =========================
> while not myRS.EOF
>
> Response.Write("<br/>CategoryName: " & myRS("CategoryName"))
>
>
> list(myRS.Fields("CategoryID").Value) = myRS.Fields("CategoryName").Value
> &
> " value"
>
>
> myRS.MoveNext()
>
> wEnd
> ========================
>



Stephen,

Thanks for your response. It explains a lot.

I think I'll omit the extra variable and use '.value' instead.

Thanks

Chris


 
Reply With Quote
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      02-02-2006
You're welcome CJM,

Good luck!

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Performance ordered dictionary vs normal dictionary Navkirat Singh Python 6 07-29-2010 10:18 AM
Re: Performance ordered dictionary vs normal dictionary Chris Rebert Python 0 07-29-2010 06:11 AM
creating a dictionary from a dictionary with regex james_027 Python 1 08-22-2007 07:39 AM
[DICTIONARY] - Copy dictionary entries to attributes Ilias Lazaridis Python 6 02-21-2006 11:27 AM
dictionary within dictionary Fox ASP General 5 03-13-2005 05:03 AM



Advertisments
 



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