PDA

Click to See Complete Forum and Search --> : reading text file


Aaron Young
Jan 24th, 2000, 12:10 AM
You can store upto 2 Billion Characters in a String Variable, you will need to change the method of Loading the File into the Variable for Larger Files though, ie.

Private Sub Command1_Click()
Dim sData As String
Dim sChunk As String
Dim lChunk As Long
Dim lFileLen As Long
Dim iFile As Integer

iFile = FreeFile
'Open File For Binary Access
Open "C:\TestFile.csv" For Binary Access Read As iFile
lFileLen = LOF(iFile)
lChunk = 64000 'Load File in 64K Chunks
While Loc(iFile) < lFileLen
'Make sure the Buffer isn't Too Big
If Loc(iFile) + lChunk > lFileLen Then lChunk = lFileLen - Loc(iFile)
sChunk = Space(lChunk)
'Get the Next Chunk of Data
Get #iFile, , sChunk
'Append it to the Rest
sData = sData & sChunk
Wend
Close iFile
MsgBox "Done"
End Sub


------------------
Aaron Young
Analyst Programmer
aarony@redwingsoftware.com
ajyoung@pressenter.com

netSurfer
Jan 24th, 2000, 12:20 AM
Thanks Aaron, I'll try that.

netSurfer
Jan 24th, 2000, 11:08 AM
I'm trying to use:

intFreeFile = FreeFile
Open strFileName For Input As #intFreeFile
Line Input #intFreeFile, strLine

to read a csv file created by an online form. The problem is that the WEB db file only seperates the lines with chr(10). When reading the line, it needs chr(13) & chr(10) at the end of each line. This results in the entire file being written into strLine. I need a method that will either change the chr(10) into chr(13) & chr(10) before I start reading the lines into my variable OR a syntax change to make the LIE INPUT look for the chr(10). Any suggestions?

Serge
Jan 24th, 2000, 11:49 AM
If you have VB6 then you can use Replace function to do the replace:


'Assuming that this is your text
Dim strText As String

strText = Replace(strText, Chr(10), vbCrLf)


strText now has the new text with Chr(10) + Chr(13) in it.

------------------

Serge

Programmer Analyst
sdymkov@microage.com
Access8484@aol.com
ICQ#: 51055819 (http://www.icq.com/51055819)

netSurfer
Jan 24th, 2000, 11:56 AM
I can replace the character once I get it in but I really need to do it Before I read from the file. I think what I would need to do is open the file and find and replace the chr(10). BUt I can't load it normally because it will load the entire CSV file into 1 string. This csv file is going to get very large and it will crash if it's all dumped into a variable. I need a way that I can open the file, repalce the chr(10) with the carriage return and line feed, save it and Then open it up normally. I have a feeling I'm not going to be able to do it in VB.

Is there a way in VB to open a file and globally replace a character Without putting it into a variable?