Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Read file more than 70k in size.

Status
Not open for further replies.

vbkris

Programmer
Jan 20, 2003
5,994
0
0
IN
hi,
i want to read a file that is more than 70k in size (contains plain text).
the problem is my usual command:
fnum=FreeFile()
Open FilePath For Input As fnum

doesnt work, it says some error like file pointer reaches end of file.

the same command works fine for small files ie upto 30k...

Known is handfull, Unknown is worldfull
 
I don't think it's the file size. I just did a quck test to print the first hundred lines in a 2 Mb text file and there were no problems:
Code:
Private Sub Command1_Click()

    Dim hFile As Long
    Dim intC1 As Integer
    Dim strTmp As String
    
    hFile = FreeFile
    Open "n:\scratch\logsource.txt" For Input As hFile
    Do Until intC1 = 100
        Line Input #hFile, strTmp
        Debug.Print strTmp
        intC1 = intC1 + 1
    Loop
    
    Close hFile
    
End Sub

Paul Bent
Northwind IT Systems
 
hi paul,
my reading line reads like this:

str=Input(LOF(fnumber),fnumber) 'read all contents at one go to str

i took this from a book.

is that the problem? since this line gave me an error only for huge text files i started doubting whether its a string problem...

Known is handfull, Unknown is worldfull
 
hi,
any idea if i can use the FileScriptingObject for this???

and one more thing, what is this EncodeFileSystem method of the file scripting object????

Known is handfull, Unknown is worldfull
 
Dim InputData As String
Set oFS = CreateObject("Scripting.FileSystemObject")
Set oTextStream = oFS.OpenTextFile(sFilePathAndName,1)
InputData = oTextStream.ReadAll
oTextStream.Close
Set oTextStream = nothing
Set oFS = nothing

I have never heard of the EncodeFileSystem method.

Swi
 
hi fellas,
i solved that problem, that file that gave me the problem was not a text file (the extensions are different).

but now i face a problem, the content of the file may be as much as 100000 characters. therefore to encode them is tough.
e.g:
strCh=""
for i=0 to 100000
strCh=strCh & "1"
next

The above thing will take a long time. is there a way to to read each and every alphabet easily in a huge string???

Known is handfull, Unknown is worldfull
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top