tags:

views:

21

answers:

1

Hi everyone,

I am working on a VB6 project and I need to extract plain text from a text file. Here is code of the function I used to do that:

Private Function FileGetText(TextFile As String) As String
Dim FileContent As String
Dim TextLine As String
Dim n As Integer
n = FreeFile
Open TextFile For Input As #n 'Open given Text File
Do Until EOF(n)
    Input #n, TextLine
    FileContent = FileContent & TextLine & vbCrLf 'Initialize text file contents line-by-line to FileContent variable
Loop
Close #n
FileGetText = FileContent 
End Function

The problem with this function is that, though it reads text from file line by line, but when encounters (,) coma in the string, it takes the suffixed string as in another line, how can I prevent it from doing so and take (,) literally??

Thanks in Advance..... :-)

+2  A: 

Input is designed for a comma delimited file, try using Line Input as follows:

Private Function FileGetText(TextFile As String) As String
 Dim FileContent As String
 Dim TextLine As String
 Dim n As Integer
 n = FreeFile
 Open TextFile For Input As #n 'Open given Text File
 Do Until EOF(n)
     Line Input #n, TextLine
     FileContent = FileContent & TextLine & vbCrLf 'Initialize text file contents line-by-line to FileContent variable
 Loop
 Close #n
 FileGetText = FileContent 
End Function
pm_2
+1 Here is the VB6 manual entry on `Line Input` http://msdn.microsoft.com/en-us/library/aa243392(VS.60).aspx
MarkJ
Thanks................ :-)
Kush