Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I read data from a text file using VB6?

Tags:

text

file-io

vb6

I need to read data from text files and use the same in my application. Im using VB 6.0. What commands do I use? Some Sample code would be highly appreciated.

like image 499
Jack Njiri Avatar asked May 20 '10 12:05

Jack Njiri


2 Answers

Here's how to read an entire text file into a string - from the VB6 manual.

Function FileToString(strFilename As String) As String
  iFile = FreeFile
  Open strFilename For Input As #iFile
    FileToString = StrConv(InputB(LOF(iFile), iFile), vbUnicode)
  Close #iFile
End Function
like image 59
MarkJ Avatar answered Sep 21 '22 07:09

MarkJ


A full tutorial and sample code can be found here

  Open Filename$ For Input As #FileHandle

  Do While Not EOF(FileHandle)        ' Loop until end of file
   Line Input #FileHandle, TextLine$  ' Read line into variable
    ' Your code here
  Loop

  Close #FileHandle
like image 21
David Sykes Avatar answered Sep 23 '22 07:09

David Sykes