String with comma delimited values to array

J

Jim

Hello:

I have a variable which contains a comma delimited list contained in a
database variable e.g. "5,6,9,10,55,42" - I want to hand this list to
an array function to get it to populate an array, such as follows
(where rst!Q10ACode is the database variable):

Dim ListArray as Variant
Dim Substring1 as String

SubString1 = rst!Q10ACode
ListArray = Array(SubString1)

________________
When I do this, it returns the string length as 14, so I know it's
getting the string, but the UBound of the array is 0, and if I try to
access ListArray(1) and get an index out of bounds error. Can someone
let me know what I'm doing wrong?

Many thanks.

Jim
 
S

Stefan Hoffmann

hi Jim,
I have a variable which contains a comma delimited list contained in a
database variable e.g. "5,6,9,10,55,42" - I want to hand this list to
an array function to get it to populate an array, such as follows
(where rst!Q10ACode is the database variable):

Dim ListArray as Variant
Dim Substring1 as String

SubString1 = rst!Q10ACode
ListArray = Array(SubString1)
Use Split():

Dim arrStrings() As String

arrStrings() = Split(rst![Q10ACode], ",")
MsgBox arrStrings(1)

You may use LBound(arrStrings()) and UBound(arrStrings()) to determine
the array boundaries.


mfG
--> stefan <--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top