?
Solved

Read a text file

Posted on 2003-03-25
9
Medium Priority
?
182 Views
Last Modified: 2010-05-01
Hello,

Well I have a *.txt file, that contains just 1 line, but its size is more then 26500 bytes, so when I read it into a text field it doesnt work.  Or at least, not the whole file is read.  So is there a way to read the whole file?  I need all the contents of that single line and not just the first 26500 bytes (I think 26500 was the number of bytes)

Please help me

0
Comment
Question by:Stofferken
[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
9 Comments
 
LVL 9

Accepted Solution

by:
GivenRandy earned 200 total points
ID: 8206182
To (quickly) read a file into a single string:

---
    Dim F As Integer
    Dim S As String

    F = FreeFile
    Open "YourFileName" For Binary As #F
    S = Space$(LOF(F))
    Get #F, , S
    Close #F
---

To read a text file and look at each line:

---
    Dim F As Integer
    Dim S As String

    On Error Resume Next
    F = FreeFile
    Open "YourFileName" For Input As #F
    If (Err.Number = 0) Then
        Do While (Not EOF(F))
            Line Input #F, S
            ' do something with S
        Loop
    End If
    Close #F
---

To read a tab-delimited (or other delimiter) file and look at each item in each line:

---
Private Sub Form_Load()
    Dim F As Integer
    Dim S As String
    Dim sArray() As String
    Dim Counter As Long

    On Error Resume Next
    F = FreeFile
    Open "YourFileName" For Input As #F
    If (Err.Number = 0) Then
        Do While (Not EOF(F))
            Line Input #F, S
            sArray = Split(S, vbTab) ' tab delimited, others are possible
            For Counter = 0 To UBound(sArray)
                Debug.Print sArray(Counter) ' do something with each element
            Next
        Loop
    End If
    Close #F
End Sub
---
0
 

Author Comment

by:Stofferken
ID: 8206241
@ GivenRandy
Well, my file is too big to do that, thats why I need help.
0
 
LVL 2

Expert Comment

by:Jacamar
ID: 8206287
a string can hold up to 2 billion characters
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 38

Expert Comment

by:PaulHews
ID: 8206443
How big is your file?
0
 
LVL 9

Expert Comment

by:dancebert
ID: 8206478
I use the TextStream object to handle text files instead of the 'Classic VB' Freefile - Open - Close statements.  However, I have no idea if TextStream has greater capacity then the classic way.  Worth a try.

You must include a refrence to Microsoft Scripting Runtime in your project to see the TextStream object.
0
 
LVL 3

Expert Comment

by:DocM
ID: 8207172

Use the RichTextBox instead of the TextBox. It has a much larger capacity.

The coding is simple:
RichTextBox1.LoadFile "FileName"
0
 

Expert Comment

by:Sandwich
ID: 8207687
try this one =P

Dim cPath as string
Dim cLineData as string

cPath = <Path> + <filename>

Open cPath For Input As #1
    While Not EOF(1)
        Line Input #1, cLineData
        With frm
            If Trim(.rtb.Text = "") Then
                .rtb.Text = cLineData + vbCrLf
            Else
                .rtb.Text = .rtb.Text + cLineData + vbCrLf
            End If
        End with
    Wend
Close #1

*rtb - RichTextbox control
0
 

Expert Comment

by:statto
ID: 8211987
You're trying to write it into a text field, ie Text1.Text, right? Or a string, ie stringname? or a Label?
0
 

Author Comment

by:Stofferken
ID: 8212026
Ok, it now works with a string
thx
0

Featured Post

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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
Course of the Month13 days, 23 hours left to enroll

801 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