Solved

remove empty elements in array

Posted on 2010-11-09
1
263 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
ID: 34092056
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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Familiarize people with the process of utilizing SQL Server views 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 Access…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

810 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