Learn how to a build a cloud-first strategyRegister Now


how to parse unknown data into array

Posted on 2006-04-17
Medium Priority
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
  • 2
  • 2

Author Comment

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

Accepted Solution

Mark_FreeSoftware earned 2000 total points
ID: 16473313

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

ID: 16473841
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

ID: 16548015
tthanx for the points, and happy coding!

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
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…
Suggested Courses
Course of the Month20 days, 17 hours left to enroll

810 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