• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 169
  • Last Modified:

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.
  • 2
  • 2
1 Solution
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
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!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now