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

--
cjmnews04@REMOVEMEyahoo.co.uk
[remove the obvious bits]

Re: Dictionary Issue by Tim

Tim
Tue Jan 31 11:43:02 CST 2006

"CJM" <cjmnews04@newsgroup.nospam> 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)
Slattery_T@bls.gov

Re: Dictionary Issue by CJM

CJM
Tue Jan 31 11:56:50 CST 2006


"Tim Slattery" <Slattery_T@bls.gov> wrote in message
news:d88vt1pt7panjtts3le1e62gtftklgkipr@4ax.com...
>>
>> 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.




Re: Dictionary Issue by stcheng

stcheng
Wed Feb 01 02:26:21 CST 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.)


Re: Dictionary Issue by CJM

CJM
Wed Feb 01 06:07:07 CST 2006


"Steven Cheng[MSFT]" <stcheng@online.microsoft.com> wrote in message
news:NR2mykwJGHA.1236@TK2MSFTNGXA02.phx.gbl...
> 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



Re: Dictionary Issue by stcheng

stcheng
Wed Feb 01 19:54:29 CST 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.)