Solved

remove empty elements in array

Posted on 2010-11-09
1
262 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Adding New Records into SQL Server Table from MS Access 4 30
Field behavior for "locked" form 12 29
Create Form using Wizard 14 35
Access 2010 Query Syntax 5 23
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…
Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

895 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

16 Experts available now in Live!

Get 1:1 Help Now