• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

TXT file with specific structure - Import

wintermute

New Member
Hi guys,
I'd like to import several dozens of text files (MEA - 3D measurements of plastic parts)
I know, how to make a code to import several files in once, but just guess, how to read text file with specific structure.
Every file has about 10 measurements points of one part - each consists:
1. line - point name (description)
2. line - 3 numbers (X, Y, Z - 3D measured coordinates, divided by comma)
3. line - 3 numbers (3D nominal coordinates, divided by comma)
I think best idea is to use arrays, but not sure how to do it. Could you please give me some hint?

Thanks
 
You can either read the files directly into Excel and use Text to Columns
or
You can read them into VBA either as a single array or line by line
Then breakit down by some rules

How about posting what you have plus a few of the files for us to test on ?
 

Hi,

a text file is a text file, nothing specific at all !

Easier to understand your needs with a source text file
and a result workbook xlsx format (no code) joined …
 
Hello Hui,

I can't use TextToColumns, there are 2 types of separators, ":" and ",".
I think read files via VBA, line by line and break them is best idea for my problem.
Till now I've made below code, need to test it, but I don't have experience with 2D arrays, I will see if it works. Thanks for any suggestions or links.

Code:
For c = 1 To allfiles
    Open filetoopen(c) For Input As #1
        Do While Not EOF(1)
            Line Input #1, importeddata
            textID = Left(importeddata, InStr(importeddata, ":"))        ' line header
            textvalue = Mid(importeddata, InStr(importeddata, ":"), 255) ' line value
            Select Case textID
                Case "Messtechnik"         ' name of 3D technician
                    Value3D(c)(0) = textvalue
                Case "Temperature"         ' temperature during testing
                    Value3D(c)(1) = textvalue  
                Case "Point"                    'measured points start with name of the Point
                    Value3D(c)(2) = textvalue
                    Line Input #1, importeddata
                    Value3D(c)(3) = Mid(importeddata, 1, InStr(importeddata, ","))
                    Value3D(c)(4) = Mid(importeddata, InStr(importeddata, ","), 255)
                    Line Input #1, importeddata
                    Value3D(c)(5)
                    .
                    .
                    .
            End Select
        Loop
    Close #1
Next c
 

Attachments

  • 3D_report.txt
    12.2 KB · Views: 10

As there is only one kind of separator by line, you can use Text2Columns !

And what about the result xlsx workbook accordingly from source text file ?‼
 
Marc L, I will try to solve it with Text2C, I didn't think I can use it with different parameter on each line. Wow.
Sample file posted, it's not a final version of report, just idea how to store data.
 

Attachments

  • sample.xlsx
    8.3 KB · Views: 6
Wintermute

A few questions
In your example import file, you have only imported the X values for the 3D data, I find that odd ?

Wouldn't you be better off doing

File 1
Pt 1 x, y, z, other fields if required
Pt 2 x, y, z, other fields if required
Pt 3 x, y, z, other fields if required
..
Pt n x, y, z, other fields if required

File 2
Pt 1 x, y, z, other fields if required
Pt 2 x, y, z, other fields if required
Pt 3 x, y, z, other fields if required
..
Pt n x, y, z, other fields if required

etc

What do you want to do with this data once you have it ?
eg: Import into Autocad, Surpac etc ?

Does the source program have an export file format that these systems can read automatically?
 

Needs a sample result workbook that reflects source text files
(second text file needed) and a crystal clear explanation …

What's column A in source text files ?
How to match by row data from several files ?
 
Back
Top