reassigning an array value in a vbscript dictionary object

below is a for next loop to decrement an dictionary array value
if the key matches it decreases the item and performs a test.
the line that errors is  
(b(i)) = (b(i))-1
and i get
error '800a0400'
Expected statement
the question is what syntax do i need to drop (b(i)) by one

for i=0 to NN_dic.Count-1
     a = NN_dic.Keys
     b = NN_dic.Items
     if strFileSubStart = (a(i))then
     (b(i)) = (b(i))-1
          if (b(i)) = 0 then
          flgStopLine = 2
          elseif(b(i))>0
          flgStopLine = 1
          else
          flgStopLine = 0
          end if
     else
     'flgStopLine = 0
     end if
next

Thanks in advance

Mark

markofsotonAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AlfaNoMoreCommented:
b(i) = (b(i) - 1)

maybe that'll work better?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
markofsotonAuthor Commented:
Doh.

try the obvious.

ah well i deserve to the lose the points for being so lazy.
0
AlfaNoMoreCommented:
sweet!! ;-)

Happy programming...
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

markofsotonAuthor Commented:
ok for some brownie points can you tell me why the
b(i) = b(i)-1 doesn't decrement the item value?
0
AlfaNoMoreCommented:
I just ran a little test using this simple code:

Set NN_dic = Server.CreateObject("Scripting.Dictionary")

NN_dic.Add "first", "4"
NN_dic.Add "second", "12"
NN_dic.Add "third", "54"

for i=0 to NN_dic.Count-1
    a = NN_dic.Keys
    b = NN_dic.Items
   
    b(i) = (Cint(b(i)) - 1)
   
    Response.Write b(i) & "<br />"
'    if strFileSubStart = (a(i))then
'    (b(i)) = (b(i))-1
'         if (b(i)) = 0 then
'         flgStopLine = 2
'         elseif(b(i))>0
'         flgStopLine = 1
'         else
'         flgStopLine = 0
'         end if
'    else
    'flgStopLine = 0
'    end if
next


And it worked fine. So how are you adding your values to your Dictionary object?
0
markofsotonAuthor Commented:
fine it'll take one off the value but it wont preserve that state, if you run your script twice it will come out at 3,11,53 at both times. now i accept this is because b(i) is an extracted value. but what i want to do is is set the dictionary (which words fine by recordset) then get a subsequent recordset to change the item's value. so

first record matches key so -1 off item
test item
second record matches key so -1 off item
test item

thanks

0
AlfaNoMoreCommented:
OK, I think we're getting closer to the problem now?

Are you saving these updated figures back into your database? Or is the dictionary object held within a session variable (or similar)?
0
AlfaNoMoreCommented:
Right, here's what I think you should do:

Open recordset;
Load recordset values (column, value) into dictionary pairs;
Process dictionary to get updated values;
Update recordset;



objRS.Open "SQL", objConn, 3, 3

Do Until objRS.EOF 'assume a single row recordset!!!!
    For Each Field In objRS.Fields
        objDict.Add Field.Name, Field.Value
    Next
    objRS.MoveNext()
Loop

'Process your Dictionary Object

'Now load back to the database
For Each Key in objDict.Keys
    objRS(Key) = objDict.Item(Key)
Next

objRS.Update() 'save new figures back to database!
0
markofsotonAuthor Commented:
The dictionary is defined by a recordset before the main recordset begins, the both work on the same table. I am trying to write a virtual file structure to the page and I want to determine when the last entry in a subDir occurs so I query the (distinct) count of the subDir and the name of the subDir and they become the dictionary item and key
so the dictionary looks like this

DU 2
DW 1
PO 5
RK 1  
 This recordset closes

The second recordset simply matches its current subfolder with the dictionary key and should take one off the dictionary value.

 I can knock one off b(i) as you have suggested but when the next record comes along the dictionary item has its original value
0
markofsotonAuthor Commented:
don't worry sussed it.

if you want to cahage an item in the dictionary then you name its key

 so

     if strFileSubStart = (a(i))then
     'ObjDictionary.Item("001") = "Leather Boots"

     NN_dic.Item(a(i)) = (b(i)-1)


works like a dream thanks for all you help, really thanks have a good one mark
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.