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


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:,main" "Return to Homepage"

"separator:" "0" "" "" ""
"text:Training Details" "0" "" ""
"text:Training Overview" "2" "" "LINK:,main"
"text:Training Application" "2" "" "LINK:,main" "Electronic Application Form"
"TEXT:Training Schedule" "2" "" "LINK:,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
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
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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

705 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