Solved

remove empty elements in array

Posted on 2010-11-09
1
261 Views
Last Modified: 2012-06-27
how do i remove unwanted empty strings from an array?

ex
processarray(0)=""
processarray(1)="280"
processarray(2)=""
processarray(3)="100"

would like the array now to be:
processarray(0)="280"
processarray(1)="100"

in access 2010 vba
0
Comment
Question by:PeterBaileyUk
1 Comment
 
LVL 42

Accepted Solution

by:
sedgwick earned 500 total points
Comment Utility
from http://www.tek-tips.com/viewthread.cfm?qid=1470647&page=9
Public Function cleanArray(varArray() As Variant) As Variant()

  Dim tempArray() As Variant

  Dim oldIndex As Integer

  Dim newIndex As Integer

  ReDim tempArray(LBound(varArray) To UBound(varArray))

  For oldIndex = LBound(varArray) To UBound(varArray)

   If Not Trim(varArray(oldIndex) & " ") = "" Then

     tempArray(newIndex) = varArray(oldIndex)

     newIndex = newIndex + 1

   End If

 Next oldIndex

 ReDim Preserve tempArray(LBound(varArray) To newIndex - 1)

 cleanArray = tempArray

End Function

Open in new window

0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

763 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now