Reading Text files

Posted on 1999-06-24
Medium Priority
Last Modified: 2010-05-02
I have a text file that look like this:

---begin file----------------------------
"text:Home" "0" "" "LINK:http://www.bae.ksu.edu/kelp/initialdoc.html,main" "Return to Homepage"

"separator:" "0" "" "" ""
"text:Training Details" "0" "" ""
"text:Training Overview" "2" "" "LINK:http://www.bae.ksu.edu/kelp/kelpinformation.htm,main"
"text:Training Application" "2" "" "LINK:http://www.bae.ksu.edu/kelp/app.html,main" "Electronic Application Form"
"TEXT:Training Schedule" "2" "" "LINK:http://www.bae.ksu.edu/kelp/classSchd.html,main" "View the Training Schedule"
----------End file--------

Here is the syntax of what you are looking at:
"Text:[Label]", "[placement]", "", "link:[Link],[target],"[hint]"

I need these paramaters separated as I read the text file and put into a ini file (I will supply the ini code), but I just need to know how to read the file so I can seperate it out.

Then I will list the item in a treeview control like this:

Level 0
   Level 2

Does anyone have anyone have an idea how to do this? Is there a way to possibly use a form Java String Delimters? I have no idea. Also text file size may be a problem if anyone can address this issue.
Question by:naallen
  • 4

Accepted Solution

tward earned 280 total points
ID: 1519545
 Dim OneLine As String
  Open Setup.txtDictionaryFileToUse.Text For Input Access Read As #1
  Do While Not EOF(1)
    Line Input #1, OneLine

    ''' Split as needed here '''
    ''' Look at the Split Function '''
  Close #1


Expert Comment

ID: 1519546
Looks good to me. I'd completely forgotten about the line input # statement, and went and reinvented the wheel the other month. Hmmm.. Time for a re-write. ;)

Expert Comment

ID: 1519547
Here's a nice little Parser for you, naallen:

Function GetWord(ByVal str As String, num As Integer)
' This gets a word. A word is either a single word seperated by spaces on both sides,
' or a collection of words inside quote marks.

' '"Hello fred"' counts as one word.
' 'th"ere"' counts as two. 'th' and 'ere'.
' 'word' counts as one word.

' Count your quotes carefully, as mistakes cannot be remedied once you have left the shop.

' You'll notice that there's no error catching. This is because there will be no errors.
' This code is 100% error free. Any changes made to it, however, may cause it to crash,
' burn and die horribly in an accident which would make Hiroshima look like a tea party.
    Const quote = """"
    Const char = " "
    Dim aChar As String
    Dim nextSpace As Long
    Dim nextQuote As Long
    Dim i As Integer
    Dim aStart As Long
    Dim aStop As Long
    Dim newStart As Long
    For i = 1 To num

        aStart = newStart
            aStart = aStart + 1
            aChar = Mid(str, aStart, 1)
        Loop While aChar = char
        If aChar = quote Then
            aStart = aStart + 1
            nextQuote = InStr(aStart, str, quote)
            aStop = nextQuote - 1
            newStart = nextQuote + 1
            nextSpace = InStr(aStart, str, char)
            nextQuote = InStr(aStart, str, quote)
            If nextQuote = 0 Or nextSpace < nextQuote Then
                aStop = nextSpace - 1
                aStop = nextQuote - 1
            End If
            newStart = aStop
        End If
        If aStop = -1 Then
            Exit For
        End If
    Next i
    If num > i Or num < 1 Then
        GetWord = Empty
        If aStop = -1 Then
            GetWord = Mid$(str, aStart)
            GetWord = Mid$(str, aStart, aStop - (aStart - 1))
        End If
    End If

End Function

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.


Expert Comment

ID: 1519548
Why would text file size be a problem?

Can't see it myself.


Author Comment

ID: 1519549
Wouldn't a very large file crash the program, I have heard that large files can do that.

Expert Comment

ID: 1519550
Providing you're not using vb3 or vb4, file size _shouldn't be a problem. If you were reading the whole file into memory before parsing it (which is what I prefer to do), then it might cause a problem if you try to open a file which is too big (and I'm talking 20+Mb files here), but reading it line by line shouldn't cause any problems.


Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

624 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