Results 1 to 6 of 6

Thread: opening a text file in VB *** Resolved***

  1. #1

    Thread Starter
    Hyperactive Member fasi's Avatar
    Join Date
    Nov 2000
    Posts
    474

    opening a text file in VB *** Resolved***

    I am trying to make a text editor in VB. I have a text box on a form and a common dialog box. How do i get the file to open in that text box
    Last edited by fasi; Jan 31st, 2004 at 06:36 PM.

  2. #2
    Frenzied Member
    Join Date
    May 2003
    Location
    So Cal
    Posts
    1,564
    Do a search for reading text files.

  3. #3
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246
    VB Code:
    1. With CommonDialog1
    2.     .Filter = "Text Files|*.txt"
    3.     .ShowOpen
    4.     Open .FileName For Input As #1
    5.     Do While Not EOF(1)
    6.     Input #1, line
    7.     Text1.Text = Text1.Text & line & vbNewLine
    8.     Loop
    9.     Close #1
    10. End With



    Hope this helps..


    Phreak

    Visual Studio 6, Visual Studio.NET 2005, MASM

  4. #4

    Thread Starter
    Hyperactive Member fasi's Avatar
    Join Date
    Nov 2000
    Posts
    474
    Thanks. Got it working

  5. #5
    Junior Member
    Join Date
    Nov 2003
    Location
    NE England
    Posts
    30
    VB Code:
    1. Dim intFile As Integer
    2.    
    3.     On Error GoTo No_Open
    4.    
    5.     intFile = FreeFile
    6.    
    7.     With cdlFiles
    8.         .Filter = "Files(*.txt)|*.txt"
    9.         .DefaultExt = "txt"
    10.         .DialogTitle = "Open File"
    11.         .Flags = cdlOFNFileMustExist + cdlOFNPathMustExist
    12.         .ShowOpen
    13.     End With
    14.  
    15.     Open cdlFiles.FileName For Input As intFile
    16.         rtfPad.Text = Input(LOF(1), intFile)
    17.     Close intFile
    18. Exit Sub
    19. No_Open:
    20. End Sub

  6. #6
    Supreme User Madboy's Avatar
    Join Date
    Oct 2003
    Location
    England
    Posts
    3,253
    Doesnt work for me

    VB Code:
    1. Public Sub OpenDocument()
    2. On Error GoTo No_Open
    3.     dlgOpen.ShowOpen
    4.         Open dlgOpen.FileName For Input As #1
    5.         Do While Not EOF(1)
    6.         Input #1, Line
    7.         txtMain.Text = txtMain.Text & Line & vbNewLine
    8.         Loop
    9.         Close #1
    10. Exit Sub
    11. No_Open:
    12. Me.Refresh
    13. txtMain.SetFocus
    14. End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width