|
-
Feb 24th, 2000, 03:59 AM
#1
Thread Starter
Member
Dead simple I'm sure - but I have no help file (no msdn CD)
How do I read the contents of a text file into a string?
THANX
Konan of the five hundred and fifty fith veriety
-
Feb 24th, 2000, 04:01 AM
#2
Here's a Function I wrote to make it really simple, (this will read any file upto 2GB in size):
Code:
Function ReadFile(ByVal FileName As String) As String
'Open Specified File and Return Data in a String
Dim iFile As Integer
Dim lFileLen As Long
Dim lChunk As Long
Dim sChunk As String
Dim sData As String
On Error GoTo ReadFileErr
iFile = FreeFile
Open FileName For Binary Access Read As iFile
lFileLen = LOF(iFile)
lChunk = 64000 'Load File in 64K Chunks
While Loc(iFile) < lFileLen
'Create a Buffer to Retrieve File Data
If Loc(iFile) + lChunk > lFileLen Then lChunk = lFileLen - Loc(iFile)
sChunk = Space(lChunk)
'Retrieve the next Chunk of Data from the File
Get #iFile, , sChunk
'Append the Chunk to the Data Retrieved so far
sData = sData & sChunk
Wend
Close iFile
'Return the File Data
ReadFile = sData
ReadFileErr:
End Function
Usage: sFileString = ReadFile("C:\TheFile.txt")
-
Feb 24th, 2000, 04:07 AM
#3
Thread Starter
Member
TA m8
I'll give it a whirl - tanx for yer code, I'll include yre name if I distribute my app - is that OK?
-
Feb 24th, 2000, 04:09 AM
#4
Sure, no problem, anything I post here is Public Domain, (anyone can use/copy/mangle any/all of it), sometimes I'll add a comment requesting a mention of Credit if they do though.
-
Feb 24th, 2000, 04:13 AM
#5
Thread Starter
Member
cool
I'm just haveing a look at how it works - when I tried useing a binary file in qbasic I just got number junk when I looked at it (numbers - no text) - but If I put it back it became the original again. However I put this to use in a cool little encryption app
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|