On Sat, 22 Nov 2008 14:27:52 -0700, "Albert D. Kallal"
<PleaseNOOOsPAMmkallal@[EMAIL PROTECTED]
> wrote:
Many thanks, just what I wanted !
>The code to direct open a text file looks like:
>
>Sub ReadTextFile
>
> Dim strFile As String
> Dim intF As Integer
> Dim strLineBuf1 As String
> Dim strLineBuf2 As String
>
> strFile = "c:\my data\MyData.txt"
>
> intF = FreeFile()
> Open strFile For Input As #intF
> Line Input #intF, strLineBuf1
> Line Input #intF, strLineBuf2
>
> Close intF
>
>So, buf1, and buf2 will have the 1st two lines from that text file.....
>
>me.MyTextBoxOnForm = strLineBuf1 & strLineBuf2
>
>If you want a carriage return between the two lines then go
>
>me.MyTextBoxOnForm = strLineBuf1 & vbcrLf & strLineBuf2
>
>If you want to read/process a whole text file and not know how many
lines,
>then a typical processing loop looks like:
>
>Sub ReadTextFile
>
> Dim strFile As String
> Dim intF As Integer
> Dim strLineBuf As String
> Dim lngLines As Long
> Dim lngBlank As Long
>
> strFile = "c:\my data\MyData.txt"
>
> intF = FreeFile()
> Open strFile For Input As #intF
>
> Do While EOF(intF) = False
> Line Input #intF, strLineBuf
> If Trim(strLineBuf) = "" Then
> lngBlank = lngBlank + 1
> Else
> lngLines = lngLines + 1
> End If
> Loop
> Close intF
>
> End If
>
> MsgBox "Number non blank lines = " & lngLines & vbCrLf & _
> "Blank lines = " & lngBlank & vbCrLf & _
> "Total = " & lngBlank + lngLines
>
>End Function
cheers,
Len


|