Question in array

Results 1 to 2 of 2

Thread: Question in array

  1. #1
    andre77 Guest

    Default Question in array

    Can you pls guide me how to delete a row from array?? <BR>For example, I have an array 20. If any row is empty or no value inside , a function will perform to delete that particular row.. <BR>Is that a way to do that in ASP??

  2. #2
    Join Date
    Dec 1969

    Default Removing rows from arrays...

    Quite simply: If you want to do this, you do it yourself.<BR><BR>In common with most every computer language in the world [yeah, there are exceptions...APL comes to mind off the top of my head...Prolog, too], VBScript (and JScript, for that matter) treats an array as a fairly primitive storage mechanism.<BR><BR>Think of an array as just a bunch of numbered holes in a wall that happen to be "grouped" with the same name. (Spaces in an egg carton work for visualization, too, if you don&#039;t get hung up on the number of spaces.)<BR><BR>You can put anything you want into any one of the holes; you can look in a hole and see what it contains; and you can remove the contents of any hole.<BR><BR>But you can NOT remove the hole itself! That wall has 23 holes [or whatever the number is], and it will continue to have 23 holes until you rebuild the entire wall.<BR><BR>NOW...what you *can* do is empty out hole number 19 [just to pick an example] and then move the contents of hole 20 into hole 19, move the contents of hole 21 into hole 20, move the contents of hole 22 into 21, and move the contents of hole 23 into hole 22. And then simply *ignore* hole 23. You have, *effectively* removed what you wanted to remove.<BR><BR>In addition to this, it turns out that VBScript allows you to "rebuild" one of those walls full of holes with a different number of holes. It than automatically copies the contents of hole N of wall 1 into hole N of wall 2 and then destroys wall 1.<BR><BR>This is done by the REDIM PRESERVE statement.<BR><BR>So... Having said all this, how can you do what you asked? At least in principle if not in actuality? Thus:<BR><BR>&#060;%<BR>Sub RemoveArrayElement( ByRef arr, elementNumber )<BR>&nbsp; &nbsp; Dim arsize, i<BR>&nbsp; &nbsp; arsize = UBound( arr )<BR>&nbsp; &nbsp; &#039; move all the elements above the given element number<BR>&nbsp; &nbsp; &#039; "down" one slot in the array...<BR>&nbsp; &nbsp; For i = elementNumber To arsize-1<BR>&nbsp; &nbsp; &nbsp; &nbsp; arr(i) = arr(i+1)<BR>&nbsp; &nbsp; Next<BR>&nbsp; &nbsp; ReDim Preserve arr(arsize-1) &#039; shrink the array by 1<BR>End Sub<BR><BR>...<BR><BR>Dim test<BR>ReDim test(3)<BR>test(0) = "This"<BR>test(1) = "is"<BR>test(2) = "not yet"<BR>test(3) = "shrunk."<BR>RemoveArrayElement test, 2<BR>...<BR>%&#062;<BR><BR>If the book you are learning ASP from doesn&#039;t present arrays clearly enough for you to understand all the above, it is time to get another book.<BR><BR><BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts