locked
Array Losing Values RRS feed

  • Question

  • I have a script that is conditionally assigning a value of one to a cell of a multi-dimensional array as it loops through it. 

    Count = 0
          ClientData = Session ("ClientData")
          for each item in ClientData(ExpertReportList)
            if Count = CLng ( Request("DeleteItem") ) then
              item(EXPERT_REPORT_DELETE) = 1
            end if
            Response.Write(Cstr(item(EXPERT_REPORT_DELETE)))        
            Count = Count + 1
          next
          
          for each item in ClientData(ExpertReportList)
            Response.Write(Cstr(item(EXPERT_REPORT_DELETE)))
          next
          Session ("ClientData") = ClientData

    The problem is that one the first pass through, the Response.Write is showing the correct values; but, on the second pass through, all of the values are back to the original values before they passed through the loop.

    Any ideas what is causing this?

    Thursday, October 2, 2014 8:29 PM

Answers

  • Since this is not an ASP support forum and we don't have access to the rest of your code (for example, we don't know what the value of EXPERT_REPORT_DELETE is or what ExpertReportList represents), it's a bit difficult to guess at the problem.

    For help with this one, rewrite as a simple VBScript script with a dummy array and a loop that you are trying to accomplish. In other words: A short, self-contained example. Please read http://sscce.org/ for the details on this principle. The idea is to present the shortest possible amount of code that makes it possible for respondents to precisely reproduce the problem you're having.


    -- Bill Stewart [Bill_Stewart]

    • Proposed as answer by Bill_Stewart Tuesday, October 7, 2014 4:51 PM
    • Marked as answer by Bill_Stewart Monday, November 10, 2014 5:59 PM
    Thursday, October 2, 2014 8:38 PM

All replies

  • Since this is not an ASP support forum and we don't have access to the rest of your code (for example, we don't know what the value of EXPERT_REPORT_DELETE is or what ExpertReportList represents), it's a bit difficult to guess at the problem.

    For help with this one, rewrite as a simple VBScript script with a dummy array and a loop that you are trying to accomplish. In other words: A short, self-contained example. Please read http://sscce.org/ for the details on this principle. The idea is to present the shortest possible amount of code that makes it possible for respondents to precisely reproduce the problem you're having.


    -- Bill Stewart [Bill_Stewart]

    • Proposed as answer by Bill_Stewart Tuesday, October 7, 2014 4:51 PM
    • Marked as answer by Bill_Stewart Monday, November 10, 2014 5:59 PM
    Thursday, October 2, 2014 8:38 PM
  • Sorry about that Bill.  I'll give a little more explanation and detail.  ExpertReportList is a table defined in a VBScript file:

    CONST ExpertReportList		 					= 43
    	CONST EXPERT_TABLE_SIZE 		= 10
    	CONST EXPERT_TYPE 					= 1
    	CONST EXPERT_LIST_OF_DOCTORS		= 2
    	CONST EXPERT_EXAM_TYPE				= 3
    	CONST EXPERT_TREATERTYPE			= 4
    	CONST EXPERT_ARCHIVE_TITLE			= 5
    	CONST EXPERT_REPORT_STATUS			= 6
    	CONST EXPERT_REPORT_DATE			= 7
    	CONST EXPERT_REPORT_ID			    = 8
    	CONST EXPERT_REPORT_DIRTY           = 9
    	CONST EXPERT_REPORT_DELETE          = 10

    In the original code example, I am doing a for each to loop through each row of the table defined in ExpertReportList.  The CONST EXPERT_REPORT_DELETE is the field in the defined table that I am changing from 0 to 1 if it meets the criteria in the IF clause.

    The problem is that if the index passed in is 1, meaning that the 2nd row in the table is to be marked for deletion, I lose that value when I come out of the routine.  That is why I have the Response.Write statements to see where I am losing the values. 

    They are there in the first Next loop; but, after I exit that loop and then run through the table entries again to verify the changed values persisted, the values that I changed did not persist.

    I was hoping that I've done something egregiously stupid enough that it would be obvious to more experienced eyes. 

    Maybe I've given enough explanation that someone can venture a guess?

    Thursday, October 2, 2014 8:52 PM
  • Remember: We don't have access to your system or your database, and we can't see your screen.

    This is a general scripting forum, not a database or an ASP support forum.

    To get help here, you will need to write a short, self-contained VBScript script that demonstrates the specific problem you're having.


    -- Bill Stewart [Bill_Stewart]

    Thursday, October 2, 2014 8:56 PM