how to parse unknown data into array

I need to allow a user to execute a sql statement such as

"SELECT FirstName, LastName, Company from ContactTable"

The SQL Statement is passed to a 3rd Party application via an API call.  I do not have direct acess to the data (can't use ADO or ODBC, etc.).

The data is then returned to me in a buffer as a string with fields delimited by "|" and records deliimited by CRLF

I can use Split to parse the buffer and put the data into a user-defined type.

The challenge is, the user can "SELECT" from many different fields.  I will not know which fields they are going to be picking.  So I am trying to figure out how to dynamically store the data in such a way that it could be displayed in a grid control.

Keep in mind, non of this can happen with data-bound controls.  It all has to happen in memory with arrays and UDT's.

Also,  it does not have to happen in VB.  If C++ or a .NET language would be more appropriate, then I could do that also.

thanks,  Kevin.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

kevinvw1Author Commented:
Also,  I do not know how many fields will be returned by the SELECT statement...

you can use strings, and convert numbers to strings with CString(number here)

and use an array of undeclared size like this:

dim tmp2() as string

Dim str As String
Dim str2() As String
Dim n As Long
str = "This is an array test"
str2 = Split(str, " ")
For n = LBound(str2) To UBound(str2)
   MsgBox str2(n)

this will give you 5 messagebox with the different words

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
kevinvw1Author Commented:
Thanks, I figured it out.  I was overthinking this.

All I needed to do was define a multi-dimensional array b(c,d).  Here is my code.

dim b() as string

' assume that a variable teststring holds records delimited by carriage-return line-feed
    z = Split(teststring, vbCrLf)
    recordcount = UBound(z)
'assume that each record has fields delimited by "|"
    y = Split(z(0), "|")
    fieldcount = UBound(y)
    ReDim b(recordcount, fieldcount)
    For c = 0 To recordcount
      rec = Split(z(c), "|")
      For d = 0 To fieldcount
        b(c, d) = rec(d)
      Next d
    Next c

tthanx for the points, and happy coding!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.