Dear All,

I want to read Content of Text File for example my test.txt file Content is "True" means i want to Show Message box as Finish how to do this .........


regards
user

Recommended Answers

All 3 Replies

Reading the contents of text file is not a problem. i couldn't understand your rest of the query... Do you mean that if there is a word "True" in your text document which if found, you want to display the message "Finish"... if yes then try this

Sub ReadtextFile()
    Dim intEmpFileNbr As Integer, Entireline As String
    
    intEmpFileNbr = FreeFile
    
    '~~> Change this with the relevant filename
    strEmpFileName = "C:\Temp\Test.txt"
    
    '~~> open the file as readonly
    Open strEmpFileName For Input As #intEmpFileNbr
    
    Do Until EOF(intEmpFileNbr)
        '~~> Read line
        Line Input #intEmpFileNbr, Entireline
        
        If InStr(1, Entireline, "True") <> 0 Then
            MsgBox "Finish"
            Exit Do
        End If
    Loop
    '~~> Close file
    Close #intEmpFileNbr
End Sub

Private Sub Form_Load()

Me.Hide

Dim intEmpFileNbr As Integer, Entireline As String

intEmpFileNbr = FreeFile


strEmpFileName = "C:\Documents and Settings\Test\Desktop\DemoCpcisd\RRC.TXT"


Open strEmpFileName For Input As #intEmpFileNbr

Do Until EOF(intEmpFileNbr)

Line Input #intEmpFileNbr, Entireline

If InStr(1, Entireline, "differences") <> 0 Then
MsgBox "OK"

Else
MsgBox "Not OK"


Exit Do
End If
Loop

Close #intEmpFileNbr
End Sub

How to check both the cases IF and Else above code is Correct or i have to do any change.

How to check both the cases IF and Else above code is Correct or i have to do any change.

what do you mean by the above?

BTW your above code is correct for "differences"

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.