how to parse unknown data into array

Posted on 2006-04-17
Last Modified: 2010-05-01
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.
Question by:kevinvw1

    Author Comment

    Also,  I do not know how many fields will be returned by the SELECT statement...
    LVL 13

    Accepted Solution


    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

    Author Comment

    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

    LVL 13

    Expert Comment

    tthanx for the points, and happy coding!

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Join & Write a Comment

    Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
    This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

    730 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

    15 Experts available now in Live!

    Get 1:1 Help Now