remove row from array

Results 1 to 2 of 2

Thread: remove row from array

  1. #1
    Join Date
    Dec 1969

    Default remove row from array

    if I know which row in an array I want to remove .. how do I remove that row .. so that all the rows "below" it are moved up

  2. #2
    Join Date
    Dec 1969

    Default *You* have to do it...

    ...there is no automatic "insert" or "remove" of array elements built into VBScript. Or, for that matter, into most computer languages. The very notion of inserting/deleting an array element is, in a way, against the point of using arrays. Typically, if you have a list that you want to insert/delete into/from, you would use some other data structure than an array.<BR><BR>Having said all that...<BR><BR>If you still want to do it:<BR><BR>&#060;%<BR>Function removeElement( fromArray, which )<BR>&nbsp; &nbsp; Dim i, newsz<BR>&nbsp; &nbsp; newsz = UBound( fromArray ) - 1<BR>&nbsp; &nbsp; For i = which To newsz<BR>&nbsp; &nbsp; &nbsp; &nbsp; fromArray(i) = fromArray(i+1)<BR>&nbsp; &nbsp; Next<BR>&nbsp; &nbsp; ReDim Preserve fromArray( newsz )<BR>&nbsp; &nbsp; removeElement = fromArray<BR>End Function<BR>%&#062;<BR><BR>As you may or may not be able to tell, that is a *VERY* "expensive" operation. Best done sparingly, if at all.<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