[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 147
  • Last Modified:

Easy Question

Can anyone give me the codes to read a text file ?

Real simple right .


0
seahpc
Asked:
seahpc
  • 2
1 Solution
 
mcriderCommented:
Here you go:


    Dim Fnum As Long
    Dim lBuf As String
    Fnum = FreeFile
    Open "C:\windows\desktop\TO DO LIST.txt" For Input Access Read As Fnum
    Do While Not EOF(Fnum)
        Line Input #Fnum, lBuf
        Debug.Print "read: " & lBuf
    Loop
    Close Fnum


Cheers!
0
 
MaximkaCommented:
1.You have to create file txt1.txt in My Documents
2.put command button on Form
and call it cmdGo
3.Set reference(Project/References...) of the project to Microsoft Scripting Runtime
4.put this code into the form

5.run the code and You will see the content of the txt1.txt on the caption of form


Private Sub cmdgo_Click()
    Dim txtFile As TextStream
    Dim cFSO As FileSystemObject
   
    Set cFSO = New FileSystemObject
    Set txtFile = cFSO.OpenTextFile("c:\My Documents\txt1.txt")
   
    Me.Caption = txtFile.ReadAll
    Set cFSO = Nothing
    Set txtFile = Nothing
End Sub


Hope this will help You.
0
 
mcriderCommented:
Thanks for the points! Glad I could help!


Cheers!
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now