Results 1 to 13 of 13

Thread: view txt file

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2004
    Posts
    5

    view txt file

    i have create a basic vb application...i using vb6. i got external file in the same folder name a.txt

    so how do i can display the text file on the vb application?

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    Welcome to the Forums.

    Here is a link to a Tutorial on File I/O
    Instead of showing the file contents to a message box, you can
    display it in a textbox by setting the textbox's .Text property to
    the value of the variable.

    HTH
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3
    Software Eng. Megatron's Avatar
    Join Date
    Mar 1999
    Location
    Canada
    Posts
    11,286
    Definetly read RobDog's tutorial.

    Here's an identical approach in binary mode. It's generally not used with ASCII files, but might prove to be slightly faster for larger files (but who's counting these days).
    VB Code:
    1. Dim sTmp As String
    2.  
    3. sTmp = Space$(FileLen("C:\myfile.txt"))
    4. Open "C:\myfile.txt" For Binary Access Read As #1
    5. Get #1, , sTmp
    6. Close #1
    7.  
    8. Text1.Text = sTmp
    Someone should add binary files to that tutorial.

  4. #4

    Thread Starter
    New Member
    Join Date
    Dec 2004
    Posts
    5
    do i need to add label or listbox to place it on my vb application and i just want to view the text file only...i got a basic application to generate number...so after user click to Generate Command button, a space of showing the text file will be apear...

  5. #5
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    Actually Mega, its B-Rabbit/Algar's Tutorial.
    Wish I could take the credit though
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  6. #6
    Software Eng. Megatron's Avatar
    Join Date
    Mar 1999
    Location
    Canada
    Posts
    11,286
    No, just a textbox and a commandbutton.

    And change the path of the file to reflect the file you want to open.

    Where are you getting Label's and ListBoxes from?

  7. #7
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    If you have multiple lines of data to display, then using a textbox
    with its .Multiline property set to True will do. Also, enable the
    scrollbars too.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  8. #8

    Thread Starter
    New Member
    Join Date
    Dec 2004
    Posts
    5
    Is it like this?


    Private Sub Text6_Change()

    Dim sTmp As String

    sTmp = Space$(FileLen("file.txt"))
    Open "file.txt" For Binary Access Read As #1
    Get #1, , sTmp
    Close #1


    End Sub
    Last edited by brainwash; Dec 2nd, 2004 at 12:26 AM.

  9. #9
    Software Eng. Megatron's Avatar
    Join Date
    Mar 1999
    Location
    Canada
    Posts
    11,286
    Put it in a command button's click() event, not the change() event of your textbox.

  10. #10

    Thread Starter
    New Member
    Join Date
    Dec 2004
    Posts
    5
    nothing appear on the textbox...my textbox name is Text6

  11. #11
    Software Eng. Megatron's Avatar
    Join Date
    Mar 1999
    Location
    Canada
    Posts
    11,286
    Did you specify the correct path?

    Did you add

    Text6.Text = sTmp

    at the end of your code?

  12. #12

    Thread Starter
    New Member
    Join Date
    Dec 2004
    Posts
    5
    oh great thanks...

  13. #13
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385
    brainwash

    You can also use an RTF Textbox and not have to write much code to read and display the file. Two to thre lines I believe.

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