Advertisement

09.03.2008 at 12:28PM PDT, ID: 23700468
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.6

Need to read delimited text file into dynamic multidimensional array

Asked by Rossamino in Visual Basic Programming

Tags:

We get delimited text files from our business partners that include part orders.  The files are supposed to be tab delimited with a specific column arrangement.  They are not.  Instead the files come in delimited with pipes "|" and commas.  Instead of being 16 columns wide, they're anywhere from 10 to 20 columns wide.  However, each of the partners is consistent which means I should be able to write a conversion program that should be easy to adapt to each of them.

So what I need to do now is figure out how to get the .TXT file into a two dimensional array so that I can loop through the rows and columns and output the columns in the correct order.  The number of records in any file can vary from 3 to 30,000 so the size of the array they're loaded into will need to be determined at run time.

I'll also need to delete any TAB characters in the original file so they don't interfere with the output file format.

I currently have an .EXE that I've put in the Send To: folder which does a conversion from Pipe delimited to Tab delimited (see attached), but I do not know how to code the additional functionality.Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
Option Explicit
Public Sub Main()
    Dim strFilename As String
    Dim strContent As String
    Dim i As Integer
    Dim strFiles() As String
    
    strFilename = Command$
    MsgBox strFilename
    If Len(strFilename) Then
    
        If InStr(strFilename, """") > 0 Then
            strFiles = Split(strFilename, """")
        Else
            strFiles = Split(strFilename, " ")
        End If
        
        For i = 0 To UBound(strFiles)
'            MsgBox strFiles(i)
            If Len(Trim(strFiles(i))) > 0 Then
                If Len(Dir(strFiles(i))) > 0 Then
                    strContent = fGetFileContents(strFiles(i))
                    strContent = Replace(strContent, vbTab, "")
                    strContent = Replace(strContent, "|", vbTab)
                    sPutStringToFile strContent, strFiles(i)
                End If
            End If
        Next i
    End If
 
End Sub
Public Function fGetFileContents(strPath As String) As String
    Dim hFile As Integer
    Dim strFileContent As String
    
    
    If Len(Dir(strPath)) = 0 Then Exit Function
    On Error GoTo errGetFile
    hFile = FreeFile
    Open strPath For Binary As #hFile
    strFileContent = Space(LOF(hFile))
    Get #hFile, , strFileContent
    Close #hFile
    fGetFileContents = strFileContent
    Exit Function
errGetFile:
    Close
    MsgBox Err.Description, vbCritical, "GetFileContents"
    
End Function
Public Sub sPutStringToFile(strContent As String, strPath As String)
    Dim hFile As Integer
    strPath = Mid(strPath, 1, Len(strPath) - 4) & "-c.txt"
   
   'If file exists delete it.
    On Error Resume Next
    Kill strPath
    On Error GoTo errPutString
    
    'Write file
    hFile = FreeFile
    Open strPath For Binary As #hFile
    Put #hFile, , strContent
    Close #hFile
    
    Exit Sub
errPutString:
 
    Close
    MsgBox Err.Description, vbCritical, "PutStringToFile"
 
End Sub
[+][-]09.03.2008 at 01:31PM PDT, ID: 22381632

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.03.2008 at 01:39PM PDT, ID: 22381716

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.03.2008 at 01:55PM PDT, ID: 22381891

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.04.2008 at 02:27PM PDT, ID: 22392893

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.08.2008 at 11:33AM PDT, ID: 22420108

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09.08.2008 at 01:28PM PDT, ID: 22421209

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.09.2008 at 01:36PM PDT, ID: 22431989

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09.10.2008 at 03:25PM PDT, ID: 22443795

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.12.2008 at 03:21PM PDT, ID: 22464385

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09.12.2008 at 03:49PM PDT, ID: 22464544

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.15.2008 at 09:42AM PDT, ID: 22480390

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09.15.2008 at 10:33AM PDT, ID: 22480888

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09.17.2008 at 09:52AM PDT, ID: 22500882

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.17.2008 at 11:35AM PDT, ID: 22502106

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09.17.2008 at 12:34PM PDT, ID: 22502737

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Visual Basic Programming
Tags: Visual Basic
Sign Up Now!
Solution Provided By: ChloesDad
Participating Experts: 2
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628