|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Remove empty elements from end of arrayWhat is the best, clean way to remove empty elements from the end of a VB
array? After I run a FilterDuplicates function that gets rid of duplicate elements and shifts the remaining elements to the lower element values, I'm left with an array that has empty elements at the end. Thank you in advance. Webbiz If you know how many elements are empty at the end, or how many elements at
the top of the array are needed then simply use Redim Preserve. Redim Preserve ArrayName(ElementCount) Look it up in MSDN Ivar Of course! How silly of me.
Thanks! Webbiz Show quoteHide quote "Ivar" <Ivar.ekstromer***@ntlworld.com> wrote in message news:89f3l.34062$I05.18939@newsfe04.ams2... > If you know how many elements are empty at the end, or how many elements > at the top of the array are needed then simply use Redim Preserve. > > Redim Preserve ArrayName(ElementCount) > > Look it up in MSDN > > Ivar > "Webbiz" <nospam@formethanks.com> wrote in If it's a dynamic array, just.....news:X3f3l.68579$5P1.14414@newsfe13.iad: > What is the best, clean way to remove empty elements from the end of a > VB array? > > After I run a FilterDuplicates function that gets rid of duplicate > elements and shifts the remaining elements to the lower element > values, I'm left with an array that has empty elements at the end. > > Thank you in advance. > > Webbiz Redim Preserve DynArray(x) .....with x being your last element. "Webbiz" <nospam@formethanks.com> wrote in message Use ReDim Preserve.news:X3f3l.68579$5P1.14414@newsfe13.iad... > What is the best, clean way to remove empty elements from the end of a VB > array? > > After I run a FilterDuplicates function that gets rid of duplicate > elements and shifts the remaining elements to the lower element values, > I'm left with an array that has empty elements at the end. While you have your answer, I thought some might find this interesting. IF
the array MyArray is a String array, then you can remove the empty cells without knowing the filled number of elements... Joined = Join(MyArray, Chr(1)) Joined = Left(Joined, InStr(Joined, Chr(1) & Chr(1)) - 1) MyArray = Split(Joined, Chr(1)) where Joined is a String variable. And, while not efficient by any means, the above can be squished together into a one-liner... MyArray = Split(Left(Join(MyArray, Chr(1)), InStr(Join(MyArray, _ Chr(1)), Chr(1) & Chr(1)) - 1), Chr(1)) You all just **knew** I had to do that, right? <g> -- Show quoteHide quoteRick (MVP - Excel) "Webbiz" <nospam@formethanks.com> wrote in message news:X3f3l.68579$5P1.14414@newsfe13.iad... > What is the best, clean way to remove empty elements from the end of a VB > array? > > After I run a FilterDuplicates function that gets rid of duplicate > elements and shifts the remaining elements to the lower element values, > I'm left with an array that has empty elements at the end. > > Thank you in advance. > > Webbiz > > > >
optional args to a class.Init method
Anyway to move Image control at runtime Dim WithEvents * As HTMLDocument with an Iframe - access denied!? Recommended IDE for the PocketPC Automatic determine .Rows in MSHFLexgrid convert Unicode string Use ColumnClick and Click Event in MSHFLexGrid asp How do you find ClassTypes Info..? RGB to CIELAB (or simply lab) color conversion |
|||||||||||||||||||||||