string parse

Posted on 2002-06-24
Last Modified: 2010-05-02
Whats the most efficient way to parse a string like this..


I need to remove the commas and assign each number to an element in an array.


Question by:JohnnyKnoxville
LVL 75

Expert Comment

by:Anthony Perkins
ID: 7106084
arrMyArray = Split("1,2,3,4,5",",")

LVL 44

Expert Comment

ID: 7106197
to be only slightly more complete:

Dim arrMyArray() as Integer
arrMyArray = Split("1,2,3,4,5",",")


Expert Comment

ID: 7106601
Dim arrMyArray() as Integer
Dim myNumbers as String
arrMyArray = Split(myNumbers,",")

this let's you split from a variable instead of hard coding the numbers into the Split function.
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

LVL 43

Accepted Solution

TimCottee earned 100 total points
ID: 7106742
Indeed you should use split, however there is a limitation that Arthur has missed and mastallama has also missed (or copied from Arthur).

The array that you split to can only be declared as String or implicitly as variant which will get a subtype of String Array.

Dim arrMyArray() As Integer

Will generate a runtime error - 13 Type Mismatch

Dim arrMyArray() As String

Will not, likewise you could declare

Dim arrMyArray As Variant

LVL 44

Expert Comment

ID: 7107108
TimCoffee, good catch.  What I posted was competely off the top of my head, as I did not have VB immediately available, so I could not test the code before I posted it.  Thanks.

Author Comment

ID: 7130957

Thanks everyone for the help.


Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

805 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