Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

multiple space-delimited files

Posted on 1999-09-26
3
Medium Priority
?
419 Views
Last Modified: 2012-05-05
I need to import text files where the records are delimited
by unknown amounts of spaces...sometimes 1, sometimes 2, etc

for example:

record1 record2      record3    record4

and I need to read each into separate arrays.
Kind of like importing a file with excel using the
"space delimited" option.

Does anyone know how to do this in Visual Basic?

Thanks

Martin
0
Comment
Question by:mlachain
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 5

Accepted Solution

by:
KDivad earned 400 total points
ID: 2077025
Tested and tried. This will sort the file into the array and will use a varying number of spaces as the delimiter. I'm not sure this is what you want, but maybe?...

    Dim FileArray() As String
    Open "C:\windows\desktop\e.txt" For Input As 1
    FT = Input(LOF(1), 1)
    Close
    Do
        If Left$(FT, 1) = " " Then
            FT = Right$(FT, Len(FT) - 1)
        Else
            y = InStr(1, FT, " ")
            X = X + 1
            ReDim Preserve FileArray(1 To X)
            If y = 0 Then
                FileArray(X) = FT
                Exit Do
            Else
                FileArray(X) = Left$(FT, y - 1)
                FT = Right$(FT, Len(FT) - y)
            End If
        End If
    Loop
0
 
LVL 10

Expert Comment

by:smegghead
ID: 2077070
If I understand your question correctly, you want to import a text file where each field is of a variable width and padded with spaces ??? if not I appologise for waffling..

This is very difficult to do without any user intervention. Excel only guesses at where the field breaks are. It's very difficult to automate this procedure. i.e. how could it know that the field value 'ABC123' is actually three separate fields of 'ABC' '12' AND '3' ??

It is possible that the fields always have at least one space between them, in which case you can go through each record looking at each character in the first couple of hundred records to determine which characters are always equal to space (ascii-32) and are followed by a non-space character for the majority of the time... but again, the best you can do is guess...
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6861934
This question was awarded, but never cleared due to the JSP-500 errors of that time.  It was "stuck" against userID -1 versus the intended expert whom you awarded.  This corrects the problem and the expert will now receive these points; points verified.

Please click on your Member Profile and select "View Question History" to navigate through any open or locked questions you may have to update and finalize them.  If you are an EE Pro user, you can also choose Power Search to find all your open questions.

This is the Community Support link, if help is needed, along with the link to All Topics which reflects many TAs recently added.

http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
http://www.experts-exchange.com/jsp/zonesAll.jsp

In efforts to help all Members maintain their open questions, this is a reminder to click your Member Profile, expand your question history and find/update all your Open and Locked questions.
 
Thank you,
Moondancer
Moderator @ Experts Exchange
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

721 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