Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

reassigning an array value in a vbscript dictionary object

Posted on 2003-04-01
10
Medium Priority
?
898 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
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
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/…
Screencast - Getting to Know the Pipeline
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…
Suggested Courses
Course of the Month14 days, 9 hours left to enroll

577 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