?
Solved

reassigning an array value in a vbscript dictionary object

Posted on 2003-04-01
10
Medium Priority
?
895 Views
Last Modified: 2012-06-21
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

0
Comment
Question by:markofsoton
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
10 Comments
 
LVL 9

Accepted Solution

by:
AlfaNoMore earned 750 total points
ID: 8244407
b(i) = (b(i) - 1)

maybe that'll work better?
0
 

Author Comment

by:markofsoton
ID: 8244473
Doh.

try the obvious.

ah well i deserve to the lose the points for being so lazy.
0
 
LVL 9

Expert Comment

by:AlfaNoMore
ID: 8244488
sweet!! ;-)

Happy programming...
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:markofsoton
ID: 8244748
ok for some brownie points can you tell me why the
b(i) = b(i)-1 doesn't decrement the item value?
0
 
LVL 9

Expert Comment

by:AlfaNoMore
ID: 8244788
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
 

Author Comment

by:markofsoton
ID: 8244845
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
 
LVL 9

Expert Comment

by:AlfaNoMore
ID: 8244918
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
 
LVL 9

Expert Comment

by:AlfaNoMore
ID: 8244948
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
 

Author Comment

by:markofsoton
ID: 8245559
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
 

Author Comment

by:markofsoton
ID: 8245644
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

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question